[英]ListActivity with Cursor
Does anyone know of a simple example that uses the CursorAdapter? 有谁知道使用CursorAdapter的简单示例? Here's what I'm doing now and it's crashing with a RuntimeException.
这是我现在正在做的事情,并且由于RuntimeException而崩溃。 I'm sure it something simple I'm missing given that I'm a newbie and can't find any simple examples of a ListView that uses a Cursor.
我肯定是我是新手,所以找不到简单的东西,因为找不到使用Cursor的ListView的任何简单示例。
Thanks, 谢谢,
... ...
public final class MyListActivity extends ListActivity { private class MyCursorAdapter extends CursorAdapter { public MyCursorAdapter(Context context, Cursor cursor) { super(context, cursor); 公共最后一个类MyListActivity扩展了ListActivity {私有类MyCursorAdapter扩展了CursorAdapter {公共MyCursorAdapter(上下文上下文,光标游标){super(context,cursor); // CRASH ...
//崩溃...
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
myDB_ = new MyDB(this);
myDB_.open();
Cursor cursor = myDB_.read();
startManagingCursor(cursor);
MyCursorAdapter adapter = new MyCursorAdapter(this, cursor);
... ...
The Notepad tutorial in the Android developer resources uses a CursorAdapter with ListView. Android开发人员资源中的记事本教程将CursorAdapter与ListView一起使用。 You can find the relevant part of the tutorial here: http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html
您可以在此处找到本教程的相关部分: http : //developer.android.com/resources/tutorials/notepad/notepad-ex1.html
You can use setViewBinder
on a SimpleCursorAdapter
to map values to views not supported by the SimpleCursorAdapter itself. 您可以在
setViewBinder
上使用SimpleCursorAdapter
将值映射到SimpleCursorAdapter本身不支持的视图。 You can see an example of using setViewBinder
to bind data from the content provider to a CheckBox here: CheckBox checked state in a ListView 您可以在此处看到使用
setViewBinder
将数据从内容提供程序绑定到CheckBox的示例: ListView中CheckBox的选中状态
You could use setViewBinder
to bind your images to your imageButtons. 您可以使用
setViewBinder
将图像绑定到imageButtons。 That way, you don't have to create your own ListAdapter. 这样,您不必创建自己的ListAdapter。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.