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.
buttonI already have amenu_filterbutton - Satanist Devilov