Capture user's choice in Dialog box from the positive button
How do I capture the user choi开发者_Python百科ce from a list of radio-buttons in the "confirm" button of the dialogbox?
The listener of the onClick event of radio-buttons can capture & act on the parameter "int which".
But I'd like to give the user a choice to change their mind even after they have made a selection, and click on "cancel" button.
To achieve this, I need to implement the functionality in the onClickListener of the "confirm" button, not that of the radiobuttons, But the "int which" of the button's listener doesn't get the value of the user's choice.
So how do I do this?
One option is to have the onClick of the radio button set some variable and not dismiss the dialog. Then when the user clicks ok, you can dismiss the dialog, and you will already have the state of the radio button stored in a variable.
in the onClick method of your confirm button loop through your RadioButtons and find which one is selected by calling rb.isChecked(). When you find the one that returns true store the value of where you are at in your loop into another variable. Then after you've pressed the confirm button you can just refer to this variable to get which one was checked.
精彩评论