Próbuję przekonwertować kod za pomocą kursorów na CursorLoaders. Aby obsługiwać starsze wersje Androida, zainstalowałem bibliotekę pomocy technicznej i zamiast importować plik android.content.CursorLoader, importuję plik android.support.v4.content.CursorLoader. Teraz kod, który skompilował dobrze, rzuca dwa błędy. Pierwszy błąd pojawia się w LoaderManager po jego wdrożeniu. Błąd: LoaderManager nie może zostać rozstrzygnięty na typ. Drugi błąd dotyczy połączenia z initLoader. Błąd: Metoda initLoader (int, Bundle, LoaderManager.LoaderCallbacks) w typie LoaderManager nie dotyczy argumentów (int, Bundle, MyList). Oto mój kod:Błąd w programie LoaderManager podczas korzystania z biblioteki pomocniczej
public class MyList extends ListActivity implements LoaderManager.LoaderCallbacks<Cursor> {
private static final String[] PROJECTION = new String[] { "_id", "fieldname" };
private static final int LOADER_ID = 0;
private static final String MYTABLE_BASEPATH = "MyTable_tbl";
private static final String AUTHORITY = "SQLData";
public static final Uri MY_URI = Uri.parse("content://" + AUTHORITY + "/" + MYTABLE_BASEPATH);
private SimpleCursorAdapter mAdapter;
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent myData = getIntent();
Bundle info = myData.getExtras();
if (info != null){
Cursor c;
String[] dataColumns = { "fieldname" };
int[] viewIDs = { R.id.mylist1 };
SimpleCursorAdapter adapter;
adapter = new SimpleCursorAdapter(this, R.layout.mylist, null, dataColumns, viewIDs, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
setListAdapter(adapter);
getLoaderManager().initLoader(0, info, this);
}
}
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String selection = "level = '" + args.getString("Level") + "'";
return new CursorLoader(this, MY_URI,
PROJECTION, selection, null, null);
}
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
switch (loader.getId()) {
case LOADER_ID:
mAdapter.swapCursor(cursor);
break;
}
}
public void onLoaderReset(Loader<Cursor> loader) {
mAdapter.swapCursor(null);
}
}
że częściowo rozwiązany tym celu importowania android.support.v4.app.LoaderManager. Ale wciąż otrzymuję ten sam komunikat o błędzie w wywołaniu initLoader. – Melanie