-3

I would like a button when pressed to do a certain thing on another screen. For example if I had 2 buttons on screen1, and when you click either of the buttons it opens another screen, however depending on which button clicked it will display a certain component.

Noname
  • 1

2 Answers2

1

You can use these two blocks to do that. When two buttons are pressed, they both open the same screen, but they have different start values. Then, on the other screen, you can use the get start value block to find out what value you got, to figure out which button was pressed.

open screen with start value and get start value blocks

John Locke
  • 185
  • 1
  • 17
0

Solution 1:

You can use two separate activities for separate components.

or

Solution 2:

Pass your button position as putExtra from first screen.

Intent i=new Intent(getApplicationContext(), NextActivity.class);
i.putExtra("btn_position",position); //pass your button positon as int 
startActivity(i);

And get the your button position using getExtra from second screen.

      Intent intent = getIntent();
      int button_postion = intent.getIntExtra("position", 0);
Fábio Santos
  • 199
  • 1
  • 2
  • 16
Ranjithkumar
  • 16,071
  • 12
  • 120
  • 159