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)
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
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.