How to get selected item of a singlechoice Alert Dialog?

后端 未结 7 1782
故里飘歌
故里飘歌 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:40

    I know this is an old post, but i just came across it, and found that this solution seems at bit more simple that whats been posted here.

    You can just do like this:

    In your onClick() handler on the dialog positive button, add the following code:

    ListView lw = ((AlertDialog)dialog).getListView();
    Object checkedItem = lw.getAdapter().getItem(lw.getCheckedItemPosition());
    

    Note that if you haven't selected any option it will crash you have to add a check here before getting the checkedItem with if(lw.getCheckedItemCount() > 0)

    0 讨论(0)
提交回复
热议问题