我有一个包含大约300000个单词的sqlite数据库字典。任何人都可以帮我解决从列表视图加载数据库的问题吗?
答案 0 :(得分:0)
我建议使用CursorAdapter。创建一个扩展CursorAdapter的类,如下所示:
public class MyCursorAdapter extends CursorAdapter {
private LayoutInflater inflater;
public MyCursorAdapter(Context context, Cursor cursor, int flags) {
super(context, cursor, flags);
inflater = LayoutInflater.from(context);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
// Change the id attribute to match your list item text view
TextView title = (TextView) view.findViewById(android.R.id.text1);
title.setText(cursor.getString(cursor.getColumnIndex(yourColumnName)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
// Change the layout to your custom list item
return inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
}
}
然后,要设置列表,您可以写:
Cursor cursor = db.rawQuery(yourQuery);
MyCursorAdapter adapter = new MyCursorAdapter(this, cursor, 0);
setListAdapter(adapter);