0

I'm facing a problem with radio buttons to save and check it again..

I have a radio group has four radiobuttons. For first attempt radiobutton in each group. When user clicks on any radiobutton and goes to next when user comeback from there, the selections made on these radiogroups/radiobuttons are gone.

How can I save/restore radiobutton selection state?

My Code..

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));
            }
            });



        }
Sam
  • 7,252
  • 16
  • 46
  • 65
Make it Simple
  • 1,832
  • 5
  • 32
  • 57

1 Answers1

0

LoadQuestions() should be written in your onCreate, so everytime you go back to the Activity, checkBox will keep their states.

If you want to keep these values for another instance of the ACtivitu, you should save the values in a Preference or in a database

Waza_Be
  • 39,407
  • 49
  • 186
  • 260
  • turn the values into a String, for instance 0,1,1,0,1, save that to a preference, and parse it when needed. – Waza_Be Aug 14 '13 at 16:51
  • Examples: http://stackoverflow.com/questions/3876680/is-it-possible-to-add-an-array-or-object-to-sharedpreferences-on-android – Waza_Be Aug 14 '13 at 16:54
  • I didn't understand, will you please work on im my code..i need to save and again i need to check that, it should not gone..please guide me.. – Make it Simple Aug 14 '13 at 16:56
  • The link I copied above is self explanatory.. In 2 minutes, you barely had time to read and to test, if you expect a full working code you are at the wrong place. Just tell us what you don't understand or what you have tried – Waza_Be Aug 14 '13 at 17:07
  • I have tried for save the value its fine but from preference i can't able to check again that.. – Make it Simple Aug 14 '13 at 17:12
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/35464/discussion-between-waza-be-and-onemanarmy) – Waza_Be Aug 14 '13 at 17:18