【发布时间】:2013-01-28 16:30:35
【问题描述】:
我正在尝试使用游标在 ListView 中显示预填充数据库(超过 100000 行)中的所有项目。它可以工作,但应用程序需要几分钟才能启动并显示 ListView。有更快的方法吗?我读过一些关于 FTS3 表的文章,有帮助吗?
我将ArrayList<HashMap<String, String>> 与 SimpleAdapter 和自定义 2 行布局一起使用。
代码:
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
}
});
}
【问题讨论】:
标签: android android-listview android-sqlite