How to get selected item of a singlechoice Alert Dialog?

后端 未结 7 1853
故里飘歌
故里飘歌 2020-12-23 13:42

I have this code to show a dialog with singlechoice(radio) options.

AlertDialog ad = new AlertDialog.Builder(this)
.setCancelable(false)
.setIcon(R.drawable.         


        
7条回答
  •  渐次进展
    2020-12-23 14:30

    1). create Array.

    final ArrayList arrData = new ArrayList();
    

    2). add data to array you have created.

    if (cursor != null) {
                if (cursor.moveToFirst()) {
                    do {
    
                        arrData .add(cursor.getString(1)); 
                                                 // (1 = int columnIndex)
    
                    } while (cursor.moveToNext());
                }
            }
    

    3). get data like this.

    public void onClick(DialogInterface dialog, int item) {
    
                            Log.d("Selected", arrData.get(item) + "");
    
                        }
    

    4). that's all :)

提交回复
热议问题