Hi, I'm getting some very jerky scrolling while using the code below to create a ListView from a Cursor. Is there something I'm doing wrong, or any way to improve the performance of this ListView?
bookmarksListView = (ListView)findViewById(R.id.bookmarks_listview);
bookmarksDbCursor = bookmarkStore.getCursor();
startManagingCursor(bookmarksDbCursor);
String[] bookmarksColumns = new String[3];
bookmarksColumns[0] = "TITLE";
bookmarksColumns[1] = "URL";
bookmarksColumns[2] = "ICONID";
int[] bookmarksViews = new int[3];
bookmarksViews[0] = R.id.title_text;
bookmarksViews[1] = R.id.subtitle_text;
bookmarksViews[2] = R.id.icon_view;
bookmarksListAdapter = new SimpleCursorAdapter(this,
R.layout.list_item,
bookmarksDbCursor,
bookmarksColumns,
bookmarksViews);
bookmarksListView.setAdapter(bookmarksListAdapter);
bookmarksListView.setOnItemClickListener(new OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(BookmarkHistoryTabActivity.this, "Clicked ID " +
Long.toString(id), Toast.LENGTH_SHORT).show();
}
});
registerForContextMenu(bookmarksListView);
Note: bookmarkStore.getCursor()
returns an unmanaged cursor from a
sqlite database containing the columns from bookmarksColumns
.
The icons I'm loading (from R.drawable) aren't the issue - I've tried turning them off and it has no effect. I've encountered a similar scrolling issue with a custom ListAdapter extending BaseAdapter I wrote a while ago, and it was caused by not properly setting the view's values in getView() I resolved it using the fix posted at http://stackoverflow.com/questions/1320478/how-to-load-the-listview-s..., but that was for a custom adapter class, and I'm not really sure how to implement that fix when I'm using a stock SimpleCursorAdapter, or if that fix even applies to this situation.
EDIT: The query returning info on the database looks like this, in case that helps:
public Cursor getCursor() {
openDB();
Cursor c = mDB.query(DB_TABLENAME, new String[]{"_id", "ICONID", "DATE", "TITLE", "URL"}, null, null, null, null,"DATE DESC");
return c;
}
EDIT2: I have no idea why, but this behavior only occurs in android 1.6+ I've tried changing my query, removing the sorting, etc. for my cursor, nothing seems to help. The database is very small (<20 items) and only contains the columns present in the query above.