I have three buttons A, B, C. The handler is the same, using the onClik10() method. The buttons have different names. These buttons opens NavigationDrawer . NavigationDrawer has a TextView .

How to make so that when clicking the button highlighted the name of the pressed button in this TextView ?

Here is my code:

 public void onClick10 (View view){ if(drawer.isDrawerOpen(Gravity.LEFT)){ drawer.closeDrawer(Gravity.LEFT); } else{ drawer.openDrawer(Gravity.LEFT); } tv.setText (дальше как писать)......??? } 

    1 answer 1

    The view that was onClick(...) method. Accordingly, it is possible to take id from this view and further spin from it.

    Example:

    activity_main.xml :

     <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:id="@+id/first_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="First button" android:onClick="onClick"/> <Button android:id="@+id/second_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second button" android:onClick="onClick"/> <TextView android:id="@+id/text_view" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout> 

    MainActivity :

     public class MainActivity extends AppCompatActivity { private Button mFirstButton; private Button mSecondButton; private TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mFirstButton = (Button) findViewById(R.id.first_button); mSecondButton = (Button) findViewById(R.id.second_button); mTextView = (TextView) findViewById(R.id.text_view); } public void onClick (View view) { switch (view.getId()) { case R.id.first_button: mTextView.setText(mFirstButton.getText()); break; case R.id.second_button: mTextView.setText(mSecondButton.getText()); break; } } }