I have cases that are attached to icons and I need to somehow implement the code instead of Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show();

 @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); switch (id) { case android.R.id.home: mDrawerLayout.openDrawer(GravityCompat.START); return true; case R.id.menu_filter: Toast.makeText(FeedActivity.this, "HELLO", Toast.LENGTH_LONG).show(); return true; } return super.onOptionsItemSelected(item); } 

Here is the code I need to implement in case:

 Button button = (Button) findViewById(R.id.button); button.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { PopupMenu popup = new PopupMenu(MainActivity.this, button); popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu()); popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { Toast.makeText(MainActivity.this, "You Clicked : " + item.getTitle(), Toast.LENGTH_SHORT).show(); return true; } }); popup.show(); } }); 

How to rewrite the code correctly so that there is no button and it could be processed normally by clicking on the icon.

  • Not sen question. You can not copy your code? - Yuriy SPb
  • @Yuriy SPb well, I have a case, the button id is registered in one of them. (menu_filter) and in it I want to write a call to the drop-down menu. - Satanist Devilov
  • So you yourself brought the code that you need to insert there. Those. you have no problem ... - YuriySPb
  • @YuriSPb it is not processed. It produces errors. and I don't need the button button at all. In the code, the listener is simply registered already, and in my first code, case listeners are already registered, the choice of which processes the code and I need to combine these two when somehow so that there are no conflicts. - Satanist Devilov
  • @Yuriy SPb PS I don’t need a button button I already have a menu_filter button - Satanist Devilov

0