CursorAdapter is slow on Android 4
I have an extended CursorAdapter class that completes a list of sentences with data from my sqlite database. So far with Android 2.3 worked well, but now in android 4.0.1 it feels very slow. Secondly, secondly, the list of proposals scrolls very slowly. Is there a known issue with the CursorAdapter in Ice Cream Sandwich? Tested on Nexus S.
Edit:
I changed my approach and tried to use CursorLoader but it still takes a long time to run the query and populate my autocomplete list.
OnCreate:
mSuggestionAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_2, null,
new String[] { "name_en", "pcode" },
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
search_text.setAdapter(mSuggestionAdapter);
getLoaderManager().initLoader(0, null, this);
OnTextChanged:
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
getLoaderManager().restartLoader(0, null, MapActivity.this);
}
CursorLoader interface:
@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
Uri baseUri = SearchableProvider.CONTENT_URI;
String select = DataBaseHelper.getWhereStatement(search_text.getText().toString());
return new CursorLoader(this, baseUri,
DataBaseHelper.SEARCHABLE_SUMMARY_PROJECTION, select, null,
"name_en" );
//return null;
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// TODO Auto-generated method stub
mSuggestionAdapter.swapCursor(data);
}
@Override
public void onLoaderReset(Loader<Cursor> arg0) {
// TODO Auto-generated method stub
mSuggestionAdapter.swapCursor(null);
}
Tried the same thing with ArrayAdapter. I get the data after a while (20 - maybe 30 seconds), but the list from Autocomplete Textview does not appear.
Delay between onCreateLoader (returns CursorLoader asynchronously) and onLoadFinished ().
source to share
SimpleCursorAdapter
deprecated for the same reasons. Google recommends using CursorLoader
instead SimpleCursorAdapter
for better speed. ArrayAdapter
is also a good idea.
http://developer.android.com/reference/android/content/CursorLoader.html
source to share