簡體   English   中英

具有游標的ListActivity

[英]ListActivity with Cursor

有誰知道使用CursorAdapter的簡單示例? 這是我現在正在做的事情,並且由於RuntimeException而崩潰。 我肯定是我是新手,所以找不到簡單的東西,因為找不到使用Cursor的ListView的任何簡單示例。

謝謝,


...

公共最后一個類MyListActivity擴展了ListActivity {私有類MyCursorAdapter擴展了CursorAdapter {公共MyCursorAdapter(上下文上下文,光標游標){super(context,cursor); //崩潰...

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);

...

Android開發人員資源中的記事本教程將CursorAdapter與ListView一起使用。 您可以在此處找到本教程的相關部分: http : //developer.android.com/resources/tutorials/notepad/notepad-ex1.html

您可以在setViewBinder上使用SimpleCursorAdapter將值映射到SimpleCursorAdapter本身不支持的視圖。 您可以在此處看到使用setViewBinder將數據從內容提供程序綁定到CheckBox的示例: ListView中CheckBox的選中狀態

您可以使用setViewBinder將圖像綁定到imageButtons。 這樣,您不必創建自己的ListAdapter。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM