Showing posts with label Get the selected radio button value outside oncheckedchanged in android?. Show all posts
Showing posts with label Get the selected radio button value outside oncheckedchanged in android?. Show all posts

Saturday, April 27, 2013

[android help] Get the selected radio button value outside oncheckedchanged in android?

Get the selected radio button value outside oncheckedchanged in android? - Stack Overflow







Tell me more ×

Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

















I am working on android. In my page I have radio buttons and I need to get the selected radio button value. My issue is I am able to get the selected radio button value only in that onCheckedChanged method. But when I am trying to print the value outside the onCheckedChanged method it is not printing. How can I get the value outside that method? Please help me out with this. I need the value outside also.



My code:

radiogroup = (RadioGroup) new RadioGroup(Page.this);

layout.addView(radiogroup);

for (int p = 0; p < arr.length; p++) {
RadioButton newRadioButton = new RadioButton(Test.this);

newRadioButton.setText(stringList6.get(p));
newRadioButton.setTextColor(Color.parseColor("#000000"));

radbtn = Integer.parseInt(stringList5.get(p));
newRadioButton.setId(radbtn);

radiogroup.addView(newRadioButton);

}


radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

public void onCheckedChanged(RadioGroup radioGroup,
int checkedId) {

for (int h = 0; h < radioGroup.getChildCount(); h++) {
RadioButton btn = (RadioButton) radioGroup.getChildAt(h);

if (btn.getId() == checkedId) {

selectedop1 = btn.getId();
System.out.println("selected radio button"+ selectedop1);

return;
}

}

}

});

























You can use getCheckedRadioButtonId method of RadioGroup, which will return id of the selected radio Button



int checkedid=radiogroup.getCheckedRadioButtonId();


Which will return radiobuttonid, if the any of the radiobutton in the RadioGroup is selected, and -1 when NO selection.























make a check whether it is checked get its value.




















default






.

stackoverflow.comm

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...