0

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

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

1 回答 1

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();
于 2012-10-30T06:24:59.217 回答