I am trying to implement a search feature in my app that will be
populated from sqlite db but am having challenges, when i test the
app in the emulator and i implemented the search feature, it crashes
and shows the following in my logcat
"Caused by: java.lang.ClassCastException:
com.akada.gemstouch.searchfeature.SearchableActivity
cannot be cast to android.support.v4.app.LoaderManager$LoaderCallbacks"
see the code below
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.content.Intent;
import android.support.v4.content.Loader;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.widget.ImageView;
import android.widget.TextView;
/**
* Created by Akinyemi on 5/8/2015.
*/
public class CountryActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<cursor> {
private Uri mUri;
private ImageView mIvFlag;
private TextView mTvName;
private TextView mTvCurrency;
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.activity_country);
Intent intent = getIntent();
mUri = intent.getData();
mIvFlag = (ImageView) findViewById(R.id.iv_flag);
mTvName = (TextView) findViewById(R.id.tv_name);
mTvCurrency = (TextView) findViewById(R.id.tv_currency);
// Invokes the method onCreateloader() in non-ui thread
getSupportLoaderManager().initLoader(0, null, this);
}
/** Invoked by initLoader() */
@Override
public Loader<cursor> onCreateLoader(int arg0, Bundle arg1) {
return new CursorLoader(getBaseContext(), mUri, null, null , null, null);
}
/** Invoked by onCreateLoader(), will be executed in ui-thread */
@Override
public void onLoadFinished(Loader<cursor> arg0, Cursor cursor) {
if(cursor.moveToFirst()){
mIvFlag.setImageResource(cursor.getInt(cursor.getColumnIndex(cursor.getColumnName(2))));
mTvName.setText("Country: "+cursor.getString(cursor.getColumnIndex(cursor.getColumnName(1))));
mTvCurrency.setText("Currency: "+cursor.getString(cursor.getColumnIndex(cursor.getColumnName(3))));
}
}
@Override
public void onLoaderReset(Loader<cursor> arg0) {
// TODO Auto-generated method stub
}
}