Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I actually found a way to do this, in case it could help someone someday, I publish my code. It works perfectly and allows to <strong>assign different popup menus and different events to the listener for one only initial button</strong>.<br> In my case, case11 corresponds to my first filter mode (Restaurants for example, and every item is a different kind of restaurant), cass12 another filter mode (nightlife for ex, with different activities for items, and so on!). </p> <pre><code>private void showPopupMenu(View v) { Bundle bundle = getIntent().getExtras(); int filterVariable = bundle.getInt("filterVariable"); switch (filterVariable) { case 11: PopupMenu myPopupMenu11 = new PopupMenu( ResultListViewActivity.this, v); myPopupMenu11.getMenuInflater().inflate(R.menu.popup_fastfood, myPopupMenu11.getMenu()); myPopupMenu11 .setOnMenuItemClickListener(new OnMenuItemClickListener() { private String filterInterval; private String filterTitle; @Override public boolean onMenuItemClick( android.view.MenuItem item) { switch (item.getItemId()) { case R.id.item11a: // define your events for item11a return true; case R.id.item11b: //.... return true; case R.id.item11c: // ... return true; } return false; } }); myPopupMenu11.show(); break; case 12: PopupMenu myPopupMenu12 = new PopupMenu( ResultListViewActivity.this, v); myPopupMenu12.getMenuInflater().inflate(R.menu.popup_restaurants, myPopupMenu12.getMenu()); myPopupMenu12 .setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick( android.view.MenuItem item) { switch (item.getItemId()) { case R.id.item12a: // .... return true; case R.id.item12b: // .... return true; } return false; } }); myPopupMenu12.show(); break; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload