2012-10-30 74 views
0

我已經寫了代碼,其中我從數據庫中獲得的結果成功綁定到listview。但現在我想在自定義對話框格式中的listview。平均值列表數據應該在dialog.How將listdata附加到自定義對話框?ListView與自定義對話框

final Cursor cursor = dbHelper.fetchAllRecords(); 
     String[] columns = new String[] { 
       RecordsDbAdapter.KEY_NAME, 
       RecordsDbAdapter.KEY_BIRTHDAY, 

     }; 
     int[] to = new int[] { 
       R.id.name, 
       R.id.birthdate, 
     }; 
     dataAdapter = new SimpleCursorAdapter(
       this, R.layout.row, 
       cursor, 
       columns, 
       to); 
     ListView listView = (ListView) findViewById(R.id.list); 
     listView.setAdapter(dataAdapter); 
+0

http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList –

+0

我已經看到,但我我無法理解如何將我的列表視圖數據添加到自定義Dialogbox.means我在ListView中獲取數據listView =(ListView)findViewById(R.id.list);如何附加它 – user1758835

+0

可能重複[對話框列表視圖和消息](http://stackoverflow.com/questions/6423706/dialog-with-list-view-and-message) –

回答

0

可以綁定適配器到AlertDialog

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
builder.setAdapter(dataAdapter, new DialogInterface.OnClickListener() { 

    @Override 
    public void onClick(DialogInterface dialog, int which) { 

     // Stuff that happens when an item is clicked 
    } 
}); 
builder.show(); 
+0

你能告訴我如何在我的代碼 – user1758835

+0

我已經包含示例代碼。這會告訴你如何實現它。 –

+0

是的它的工作,我們可以在那裏實施複選框嗎?並從中獲取檢查的項目? – user1758835