我正在努力争取一个简单的Alertdialog
填充来自SQLLite
数据库的选择。我能够验证cursor
实际上是否包含我从database
中选择的有效数据,但是Alertdialog
中没有显示这些元素。我使用setItems()
或setAdapter()
使用相应的示例数据元素(以编程方式创建用于测试目的)进行测试,并且也不显示这些列表。所以,我似乎在做一些基本的错误。
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mActivityMain);
alertDialogBuilder.setTitle("Manage logbooks");
alertDialogBuilder.setMessage("Click logbook for further actions");
alertDialogBuilder.setCancelable(true);
final Cursor cursor = mActivityMain.getDatabase().get_table_logbooks_cursor_by_id(0);
alertDialogBuilder.setCursor(cursor, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
AlertDialog.Builder builderInner = new AlertDialog.Builder(mActivityMain);
builderInner.setTitle("Your selected Item is");
builderInner.setMessage(new DatasetLogbook(cursor).getName());
builderInner.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builderInner.show();
}
}, "name");
alertDialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
alertDialogBuilder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
final AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();