Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

349
Vistas
Buttons cannot be clicked inside nested switch case

I have this situation where I have to use 3 buttons multiple times like:

"Where are you from" and the choices are: button1, button2, button3. if button 1 is picked then there will be a new question, using the same buttons, but with different texts. If button 2 is picked then there will be a different question and so on.

There will be layers for this so buttons will change 64 times. I am struggling with the logic for the 3rd layer.

I created codes for the branch of button1:

text.setText("Where are you from?"); //this is the 1st layer
        btn1.setText("Asia")
        btn2.setText("Europe")
        btn3.setText("North America")
case R.id.button:
        branch = 1;
        if (branch == 1) //this is the 2nd layer
        choice = "Where in Asia are you from?"
        text.setText(choice);
        btn1.setText("East Asia");
        btn2.setText("Southeast Asia");
        btn3.setText("Northeast Asia");
        break;  
        }
switch (view.getId()) {
        case R.id.button:
        choice = "Where in East Asia?" //this is the third layer
        text.setText(choice);
        btn1.setText("insert country");
        btn2.setText("insert country 2");
        btn3.setText("insert country 3");
        break;

        case R.id.button2:
        choice = "Where in Southeast Asia"; //this is the third layer
        text.setText(choice);
        btn1.setText("insert country");
        btn2.setText("insert country 2");
        btn3.setText("insert country 3");
        break;

        case R.id.button3:
        choice = "Where in Northeast Asia?"; //this is the third layer
        text.setText(choice);
        btn1.setText("insert country");
        btn2.setText("insert country 2");
        btn3.setText("insert country 3");
        break;

the branch for where in east Asia? where in southeast Asia? where in northeast Asia? does not appear when I run it. Both textview and buttons cannot be seen for the third layer (When button is clicked in layer 2, it stays in layer 2)

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You should think about a better data structure to handle this logic. This gets unhandable the more layers you add. Here is a simple idea how separate logic from representation:

Question-Class

  • has a Question-String
  • has a Map<String, Question>: String is an answer and Question is the following Question for this given answer

So this ends up in a tree structure.

Representation Layer: The textfield and the buttons only show informations related to the selected question. They don't handle any logic. Your textfield shows the Question-String. Your buttons show the answers in the list one by one.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda