我已经编写了代码,我从数据库中获取结果,我已成功绑定到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);
答案 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();