Show information depending on which button was pressed

I am making an informational app for Android, and I cannot figure out how to change a button depending on which button was pressed in the previous class.

I took this photo which shows how the application works:

Flowchart

After pressing the first button, you get into a new class with two new buttons that send you to the same class, but 3 buttons should change depending on which of the two buttons you pressed, the three buttons that you get sent to send you one and the same class, but there is a TextView that changes the text depending on which button you clicked.

So, I need to add some information to the button (intention?) So that it finds out that you clicked earlier.

I'm new to Java and Android, so I'm sorry if I explain it in a weird way.

Thanks in advance

+5
source share
1 answer

Each time you start a new action, but some additional functions in this intent inform about the next action that the buttons should display. In the next exercise, read more about the intentions you received and program your button text accordingly.

Here is some psuedo code.

public class FirstActivity extends Activity{

   //setup button 1 and two first, then set their onClickLiseners like so

   View.OnClickListener clickListener = new View.OnClickListener(){
      public void onClick(View view){
        Intent newActivity = new Intent(FirstActivity.this, SecondActivity.class);
        if(view == button1){
          //add extra to intent indicating button1 was clicked
        }
        else{
          //add extra to intent indicating button2 was clicked
        }
        startActivity(newActivity);
      }
    };


  // other stuff in your activity
}


public class SecondActivity extends Activity{

  protected void onCreate(Bundle icicle){
     Intent startedBy = getIntent();
     if(started by has the extra indicating button 1 was clicked){
       //do button1 stuff
     }
     else{
       //do button2 stuff 
     }
   }
}


}
+3
source

All Articles