开发者

android - controlling state of RadioButton

开发者 https://www.devze.com 2023-01-07 15:02 出处:网络
i am gettin 1 problem in d android application that i have made. -> i have a 3 RadioButton\'s on 1 activity screen

i am gettin 1 problem in d android application that i have made.

-> i have a 3 RadioButton's on 1 activity screen

-> after a Button is pressed(on same activity) the text associated with all of them should change and all RadioButton's must be unchecked and should be clickable

the text is changing properly and the RadioButton's are becoming unchecked but the problem am facing is that:

    开发者_如何学Go
  1. if suppose RadioButton 1 is selected and then after pressing the Button am unable to click that same RadioButton until i click some other RadioButton.

Why so??


the solution is for future readers

create RadioGroup instance in .java file and call instance.clearCheck()


Do not use RadioButton.setChecked method directly. Use RadioGroup.check method to check RadioButton programmabaly

rg = (RadioGroup) findViewById(R.id.myFavouriteGroup);
int selectedItem = 0; // the fist item in rgGroup must be selected
.... do something ....
if (selectedItem >= 0)
{
   rg.check(rg.getChildAt(selectedItem).getId());
}
....

After this user can change selected item to another.


Part1

RadioButton option1  = (RadioButton) findViewById(R.id.RadioButton01);
option1.setText(temp.substring(answerCount[0]+1, answerCount[1]));

if(option1.isChecked())
{
    score+=1;
}

Part2

option1.setChecked(false);
option1.setClickable(true);
option1.setText(temp.substring(answerCount[aCount]+1, answerCount[aCount+1]));

Part 1 is executed Ist and then Part 2 is a part of 1 of my methods.. is that enough??

0

精彩评论

暂无评论...
验证码 换一张
取 消