带有自定义对话框的ListView

时间:2012-10-30 06:20:48

标签: android listview customdialog

我已经编写了代码,我从数据库中获取结果,我已成功绑定到listview。但是现在我想要自定义对话框格式的listview.Means列表数据应该出现在对话框中。如何将listdata附加到自定义对话框?

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

1 个答案:

答案 0 :(得分: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();