Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

346
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!