Click here to Skip to main content

Katherine99 asked:

Open original thread
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.
Tags: Android, checkbox

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).



Advertise | Privacy | Mobile
Web03 | 2.8.140921.1 | Last Updated 26 Mar 2009
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