lundi 18 novembre 2019

How to make item visible only if statement boolean in android

I have static constant top navigation menu with the following item

<item
    android:id="@+id/action_camera"
    android:enabled="true"
    app:showAsAction="always" />
<item
    android:id="@+id/action_gallery"
    android:enabled="true"
    app:showAsAction="always" />

and I have two class MainActivity and SecondActivity

I wanna make both item appear only if condition met

Exemple : If user clicked on second Activity display both item.

MainActivity

//action bar menu
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
     //inflate menu
     getMenuInflater().inflate(R.menu.top_navigation_menu, menu);
     return true;
 }
 //handle actionbar item clicks
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
     int id = item.getItemId();
     if (id == R.id.action_camera){
         //OpenCamera
     }
     if (id == R.id.action_gallery){
         //OpenGallery
     }
     return super.onOptionsItemSelected(item);
 }

Aucun commentaire:

Enregistrer un commentaire