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(con开发者_JS百科text, 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. You can find the relevant part of the tutorial here: 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. 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
You could use setViewBinder
to bind your images to your imageButtons. That way, you don't have to create your own ListAdapter.
精彩评论