I'm trying to display all the items from a pre-filled database (with over 100000 rows) in a ListView using cursors. It works, but it takes a couple of minutes for the app to start and show the ListView. Is there a faster way? I've read something about FTS3 tables, would that help?
I'm using ArrayList<HashMap<String, String>>
with a SimpleAdapter and custom 2-line layout.
Code:
Cursor cursor = sDictionary.query("FTSgesla", new String[] {PodatkovnaBaza.KEY_WORD, PodatkovnaBaza.KEY_DEFINITION}, null, null, null, null, PodatkovnaBaza.KEY_WORD);
if (cursor == null)
{
// There are no results
mTextView.setText("Empty");
}
else
{
HashMap<String, String> item;
if(cursor.moveToFirst())
{
do
{
item = new HashMap<String, String>();
item.put("line1", cursor.getString(0));
item.put("line2", cursor.getString(1));
list.add(item);
}
while(cursor.moveToNext());
}
sa = new SimpleAdapter(GlavniActivity.this, list,
R.layout.result,
new String[] { "line1","line2" },
new int[] {R.id.word, R.id.definition});
mListView.setAdapter(sa);
// Define the on-click listener for the list items
mListView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//do something
}
});
}