带光标的 ListActivity
有谁知道使用 CursorAdapter 的简单示例?这就是我现在正在做的事情,它因运行时异常而崩溃。鉴于我是新手并且找不到使用 Cursor 的 ListView 的任何简单示例,我确信我缺少一些简单的东西。
谢谢,
...
公共最终类 MyListActivity 扩展了 ListActivity { 私有类 MyCursorAdapter 扩展 CursorAdapter { public MyCursorAdapter(上下文上下文,光标光标) { 超级(上下文,光标); // 碰撞 ……
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);
Does anyone know of a simple example that uses the CursorAdapter? Here's what I'm doing now and it's crashing with a 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.
Thanks,
...
public final class MyListActivity extends ListActivity
{
private class MyCursorAdapter extends CursorAdapter
{
public MyCursorAdapter(Context context, Cursor cursor)
{
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);
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Android 开发人员资源中的记事本教程使用 CursorAdapter 和 ListView。
您可以在这里找到本教程的相关部分:
http://developer.android.com/resources/tutorials/notepad/记事本-ex1.html
The Notepad tutorial in the Android developer resources uses a CursorAdapter with ListView.
You can find the relevant part of the tutorial here:
http://developer.android.com/resources/tutorials/notepad/notepad-ex1.html
您可以在
SimpleCursorAdapter
上使用setViewBinder
将值映射到 SimpleCursorAdapter 本身不支持的视图。您可以在此处查看使用setViewBinder
将内容提供程序中的数据绑定到 CheckBox 的示例:ListView 中的复选框选中状态您可以使用
setViewBinder
将图像绑定到 imageButtons。这样,您就不必创建自己的 ListAdapter。You can use
setViewBinder
on aSimpleCursorAdapter
to map values to views not supported by the SimpleCursorAdapter itself. You can see an example of usingsetViewBinder
to bind data from the content provider to a CheckBox here: CheckBox checked state in a ListViewYou could use
setViewBinder
to bind your images to your imageButtons. That way, you don't have to create your own ListAdapter.