我遇到了单选按钮的问题,需要保存并再次检查..
我有一个广播组有四个radiobuttons。对于每组中的第一次尝试radiobutton。当用户点击任何单选按钮并在用户从那里回来时进入下一个单选按钮时,对这些无线电组/无线电按钮的选择就会消失。
如何保存/恢复单选按钮选择状态?
我的代码..
private void LoadQuestions() {
ques1.add("whats the name?");
ques1.add("whats place?");
ques1.add("whats the favourite?");
ques1.add("whats the game?");
ques1.add("whats the time?");
answ1.add("A");answ1.add("B");answ1.add("C");answ1.add("D");
answ1.add("MDU");answ1.add("MS");answ1.add("CHE");answ1.add("POND");
answ1.add("1");answ1.add("2");answ1.add("3");answ1.add("4");
answ1.add("VB");answ1.add("TENN");answ1.add("HOC");answ1.add("CRI");
answ1.add("11");answ1.add("12");answ1.add("13");answ1.add("14");
quetxt = (TextView) findViewById(R.id.que_txt);
quetxt.setText("Q" + num + ")" + ques1.get(i));
btn_practice1.setText(answ1.get(0));
btn_practice2.setText(answ1.get(1));
btn_practice3.setText(answ1.get(2));
btn_practice4.setText(answ1.get(3));
Button nextBtn = (Button) findViewById(R.id.nxt_btn);
nextBtn.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
if (i == ques1.size() -1) {
showAlert();
}else{
++i;
++num;
TextView quetxt = (TextView) findViewById(R.id.que_txt);
quetxt.setText("Q" + num + ")" +ques1.get(i));
++k;
btn_practice1.setText(answ1.get((k*4)+0));
btn_practice2.setText(answ1.get((k*4)+1));
btn_practice3.setText(answ1.get((k*4)+2));
btn_practice4.setText(answ1.get((k*4)+3));
btn_practicerg.clearCheck();
}
}
private void showAlert() {
// TODO Auto-generated method stub
}
});
Button previousbtn1 = (Button) findViewById(R.id.accbtn);
previousbtn1.setOnClickListener(new Button.OnClickListener(){
public void onClick(View v){
--i;
--num;
TextView quetxt = (TextView) findViewById(R.id.que_txt);
quetxt.setText("Q" + num + ")" + ques1.get(i));
--k;
btn_practice1.setText(answ1.get((k*4)+0));
btn_practice2.setText(answ1.get((k*4)+1));
btn_practice3.setText(answ1.get((k*4)+2));
btn_practice4.setText(answ1.get((k*4)+3));
}
});
}
答案 0 :(得分:0)
LoadQuestions()
应该写在你的onCreate中,所以每当你回到Activity时,checkBox都会保留它们的状态。
如果要将这些值保留在ACtivitu的另一个实例中,则应将值保存在首选项或数据库中