1
我正在使用android。在我的頁面我有單選按鈕,我需要獲得選定的單選按鈕值。我的問題是我能夠得到所選的單選按鈕 值只在onCheckedChanged方法。但是當我試圖打印onCheckedChanged方法外的值時,它不打印。 如何獲得該方法之外的值?這個你能幫我嗎。我也需要外面的價值。在android中獲取oncheckedchanged之外的選定單選按鈕值?
My code:
radiogroup = (RadioGroup) new RadioGroup(Page.this);
layout.addView(radiogroup);
for (int p = 0; p < arr.length; p++) {
RadioButton newRadioButton = new RadioButton(Page.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 inside"+ selectedop1);
return;
}
}
}
});
System.out.println("selected radio button outside"+ selectedop1);