Android AlertDialog和游标

Android AlertDialog和游标,android,android-alertdialog,android-cursor,Android,Android Alertdialog,Android Cursor,我已经使用光标构建了一个AlertDialog来填充对话框中的列表项。所有这些都可以很好地创建列表 我甚至在所选行的回调中返回“which”项。还有一个问题 如何获取已单击项目的文本 我不想重新查询光标并通过结果旋转到“which”项,但我不知道如何获得值 谢谢 protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_GENUS_LIST_CURSOR: Cursor

我已经使用光标构建了一个AlertDialog来填充对话框中的列表项。所有这些都可以很好地创建列表

我甚至在所选行的回调中返回“which”项。还有一个问题

如何获取已单击项目的文本

我不想重新查询光标并通过结果旋转到“which”项,但我不知道如何获得值

谢谢

protected Dialog onCreateDialog(int id) {
    switch (id) {
        case DIALOG_GENUS_LIST_CURSOR:
            Cursor cursor = managedQuery(AquaNotesDbContract.Genus.CONTENT_URI,
                    GenusQuery.PROJECTION, null, null, null);
            return new AlertDialog.Builder(Gallery.this)
                        .setTitle(Res.string.select_genus)
                        .setCursor(cursor,
                    new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                    /* an item was selected */  
                            < this is where I want to learn the text selected??? >                  
                            }
                        },
                    GenusQuery.PROJECTION[GenusQuery.COMMON_NAME])
                        .create();
    }
    return null;
}
受保护的对话框onCreateDialog(int-id){
开关(id){
案例对话框\u属\u列表\u光标:
Cursor Cursor=managedQuery(AquaNotesDbContract.Genus.CONTENT_URI,
GenusQuery.PROJECTION,null,null,null);
返回新的AlertDialog.Builder(Gallery.this)
.setTitle(Res.string.select_属)
.setCursor(游标,
新建DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,int which){
/*已选择一个项目*/
<这是我想学习所选文本的地方???>
}
},
GenusQuery.PROJECTION[GenusQuery.COMMON\u NAME])
.create();
}
返回null;
}

在onClick处理程序中

cursor.moveToPosition(which); cursor.getString(GenusQuery.PROJECTION.INDEX_OF_COLUMN_OF_TEXT_YOU_WANT); 游标。移动位置(which); cursor.getString(所需的文本列的GenusQuery.PROJECTION.INDEX);
很好,谢谢。我想我第一次尝试这样的东西时就被一个范围错误搞砸了。我所要做的就是将光标定义为“final”,以使您的解决方案有效。