What I want to achieve:
I have a custom ListView adapter. To each Listitem I want to add a popup menu, pretty similar to the ListView in the current Google Play appl
popup = (Button)findViewById(R.id.button);
popup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
PopupMenu popup = new PopupMenu(MainActivity.this,view);
popup.getMenuInflater().inflate(R.menu.popup_menu,popup.getMenu());
popup.show();
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
if(id==R.id.install){
show_toast("Install Clicked");
}else{
show_toast("WishList Clicked");
}
return true;
}
});
}
});
public void show_toast(String message){
Toast.makeText(this,message,Toast.LENGTH_SHORT).show();
}
Note:
Don't forgot to import this....
import android.support.v7.widget.PopupMenu;
import android.view.MenuItem;