[Solved] how to know witch button of three buttons is clicked full solution please android studio


I would suggest you revisit your design, I don’t know what you’re trying to achieve, but it doesn’t look like the best way to do it.

Anyways, you can pass arguments to another Activity like this. Let’s say user clicks on button 2 and button 3.

Main1Activity:

//button1 onClick
@Override
    public void onClick(View v) {
        Intent intent = new Intent(this, Main2Activity.class);
        Bundle b = new Bundle();
        b.putInt("firstPressedButton", 2); //Your first button pressed
        intent.putExtras(b); 
        startActivity(intent);
}

Main2Activity:

int firstPressedButton = -1;

@Override
    public void onCreate(Bundle savedInstanceState) {
        //init activity

        Bundle b = getIntent().getExtras();
        if(b != null)
            firstPressedButton = b.getInt("firstPressedButton");
}

//button3 onClick, do similar for other buttons
@Override
    public void onClick(View v) {
        if(firstPressedButton == 1){
             Intent intent = new Intent(this, Main6Activity.class);
             startActivity(intent);
        }
        if(firstPressedButton == 2){
             Intent intent = new Intent(this, Main7Activity.class);
             startActivity(intent);
        }
        if(firstPressedButton == 3){
             Intent intent = new Intent(this, Main8Activity.class);
             startActivity(intent);
        }
    }

1

solved how to know witch button of three buttons is clicked full solution please android studio