Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

355
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda