1
我使用SimpleCursorAdapter
来管理我的查询到数据库,然后显示在ListView
结果的CursorAdapter。的Android SimpleCursorAdapter到
这里是我的代码:
database.open();
ListView listContent = (ListView)findViewById(android.R.id.list);
Cursor c = database.getData();
startManagingCursor(c);
String[] from = new String[]{Database._GROUP_NAME};
int[] to = new int[]{android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, query, from, to);
listContent.setAdapter(adapter);
database.close();
虽然在第一次看,就它的工作如预期,我认为,这不应该继续,因为有CursorAdapter
的方式。
我知道,这是一个noob问题,但由于刚刚起步,目前已经在Android的编程我仍然不知道多少。
我怎样才能通过这个使用SimpleCursorAdapter
到CursorAdapter
? 已经搜索互联网上,但无法知道如何可以做到这一点。
不问代码只是一些方向。
感谢
favolas
更新后mainu COMMENT
database.open();
ListView listContent = (ListView)findViewById(android.R.id.list);
Cursor c = database.getData();
MyAdapt cursorAdapter = new MyAdapt(this, query);
listContent.setAdapter(adapter);
database.close();
MyAdapt类:
public class MyAdapt extends CursorAdapter {
private final LayoutInflater mInflater;
public MyAdapt(Context context, Cursor c) {
super(context, c);
mInflater = LayoutInflater.from(context);
mContext = context;
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView groupName = (TextView) view.findViewById(android.R.id.text1);
groupName.setText(cursor.getString(cursor
.getColumnIndex(Database._GROUP_NAME)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
final View view = mInflater.inflate(
android.R.layout.simple_list_item_1, parent, false);
return view;
}
}
这是正确的方法是什么?
favolas
创建一个类SimpleCursorAdapter这将延长一个CursorAdapter。你会得到一些默认的overRideed方法。 UU将被清除,然后 – mainu 2012-07-30 11:39:32
@mainu谢谢。请参阅我的更新 – Favolas 2012-07-30 15:05:38