android alertdialog.builder setCursor

时间:2015-06-22 15:31:20

标签: android alertdialog

我正在努力争取一个简单的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();

0 个答案:

没有答案