Android SimpleCrsorAdapter到光标Adapter
我正在使用Android SimpleCrsorAdapter到光标Adapter,android,simplecursoradapter,android-cursorloader,Android,Simplecursoradapter,Android Cursorloader,我正在使用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
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
?
已经在互联网上搜索过,但无法理解如何做到这一点
不是问代码,只是问一些方向
谢谢
法沃拉斯
在mainu评论后更新
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;
}
}
这是正确的方法吗
favolasSimpleCursorAdapter是可用于自定义适配器的最简单的适配器形式。
您应该仅在不需要任何自定义的情况下使用SimpleCrsorAdapter。创建一个类SimpleCrsorAdapter,该类将扩展CursorAdapter。默认情况下,您将获得一些重写方法。UU将被清除then@mainu谢谢请看我的更新