Q:

Detect which button is clicked

i have 3 button in my page :
red, blue and green
how i can detect which button is clicked 
i want use the background color for next page(red,blue or green)
this is my code in main page:
public void color(View view) {
    Intent color= new Intent(this, colorPage.class);
    Click(view);
    String What_color = view.toString();
    color .putExtra("What_color",What_color);
    startActivity(colorPage);
}

private void Click(View view1) {
    int id = view1.getId();
        }

}
and this is my code in colorPage:
Bundle What_color = getIntent().getExtras();
    if (What_color != null) {
        String mycol = What_color.getString("What_color");
        TextView result = (TextView) findViewById(R.id.tResult);
        result.setText(mycol);
    }

i see in textView this code:
android.support.v7.widget.AppCompatButton{366bb1b VFED..C. ...P.... 0,0-728,114 #7f070023 app:id/Red
or this code:
ndroid.support.v7.widget.AppCompatButton{366bb1b VFED..C. ...P.... 0,0-728,114 #7f070023 app:id/Blue
please help me

A:

    you can create a global string like 

    String detectBtnStr = "";

    private void Click(View view1) {
        int id = view1.getId();

    switch(id){

    case: R.id.red_btn:
    detectBtnStr = "red";
    break;

    case: R.id.blue_btn:
    detectBtnStr = "blue";
    break;

    case: R.id.green_btn:
    detectBtnStr = "green";
    break;
    }

            }

and when come back then check with detectBtnStr like

 if (detectBtnStr.equals("red")) {
            // do your code}
        else if (detectBtnStr.equals("blue")) {
                // do your code
            }
            else if (detectBtnStr.equals("green")){
            // do your code
            }

hope this will help you.

