2012-03-16 31 views
0

我使用游标构建了一个AlertDialog来填充对话框中的列表项。所有与创建列表一起工作良好。Android AlertDialog和游标

我甚至在选择的行的回调中返回'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; 
} 

回答

1

如何在onclick处理程序...

 
cursor.moveToPosition(which); 
cursor.getString(GenusQuery.PROJECTION.INDEX_OF_COLUMN_OF_TEXT_YOU_WANT); 
+0

这工作太好了,谢谢。我想我第一次尝试这样的事情时被范围错误搞乱了。我所要做的就是让你的解决方案工作,将游标定义为'final'。 – HeneryH 2012-03-17 02:12:22