Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Android checkbox
Hi all, I'm working in an app which basically consists of a number of pages with one question each and 4 possible answers byradioButtons. I'm trying to save the clicked radioButton in case the user has selected it and in case the user hasn't selected any button or is the first time the question is shown ( the user can go backwards and towards) show the radioButton checked as false. I will appreciate some help in order to save the info and show properly the radiobuttons. Here are some fractions of the code:
 
radGrp = (RadioGroup) findViewById(R.id.respuestas3RG);
        radBotA = (RadioButton) findViewById(R.id.respuesta3A);
        radBotB = (RadioButton) findViewById(R.id.respuesta3B);
        radBotC = (RadioButton) findViewById(R.id.respuesta3C);
        radBotD = (RadioButton) findViewById(R.id.respuesta3D);
        NombrePrueba = (Button) findViewById(R.id.botonprueba);
        bPrevious = (Button) findViewById(R.id.botonantes);
        bNext = (Button) findViewById(R.id.botondespues);
        bFinalizar = (Button) findViewById(R.id.botonfinalizar);
 
        pregunta = (TextView) findViewById(R.id.enunciado3);
        enunciado = (ImageView) findViewById(R.id.imagen3);
 
         questions = new Questions();
         currentQuestion();
 
        // VisibilityNext();
         //pruebaEstados
         if(radBotA.isChecked()){
            Respuestas[posicion]="A";
         }else if (radBotB.isChecked()){
             Respuestas[posicion]="B";
         }
         else if (radBotC.isChecked()){
            Respuestas[posicion]="C";
         }
         else if (radBotD.isChecked()){
             Respuestas[posicion]="C";
         }
 

bPrevious.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
 
            posicion = posicion -1;
            questions.Previous();
            currentQuestion();
 
            if (Respuestas[posicion].equals("A")){
                radBotA.setChecked(true);}
                else if (Respuestas[posicion].equals("B")){
                    radBotB.setChecked(true);}
                else if (Respuestas[posicion].equals("C")){
                    radBotC.setChecked(true);}
                else if (Respuestas[posicion].equals("D")){
                    radBotD.setChecked(true);}
            //checked
            else{
                    radBotA.setChecked(false);
                    radBotB.setChecked(false);
                    radBotC.setChecked(false);
                    radBotD.setChecked(false);
            }
        }
    });
    bNext.setOnClickListener(new View.OnClickListener(){
        @Override
            public void onClick(View v) {
            posicion = posicion +1;
            questions.Next();
            currentQuestion();
            if (Respuestas[posicion].equals("A")){
                radBotA.setChecked(true);}
                else if (Respuestas[posicion].equals("B")){
                    radBotB.setChecked(true);}
                else if (Respuestas[posicion].equals("C")){
                    radBotC.setChecked(true);}
                else if (Respuestas[posicion].equals("D")){
                    radBotD.setChecked(true);}
 
            //checked
            else{
                    radBotA.setChecked(false);
                    radBotB.setChecked(false);
                    radBotC.setChecked(false);
                    radBotD.setChecked(false);
 

            }
        }
 
However the function doesnt doe what it should do. For instance If I select the B answer and I go to the previous question the only thing that these makes is that i cannot select in that question the answer B.
Posted 28-Jan-13 11:28am

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.140926.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100