Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Androidcheckbox
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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 530
1 OriginalGriff 379
2 Manas Bhardwaj 350
3 Abhinav S 295
4 Sampath Lokuge 255
0 Sergey Alexandrovich Kryukov 7,647
1 OriginalGriff 4,287
2 Peter Leow 3,681
3 Maciej Los 3,515
4 Er. Puneet Goel 3,107


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