Click here to Skip to main content
15,891,657 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

C#
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";
         }



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

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900