我想顯示菜單,當點擊一個特定的形象:菜單按鈕的工作原理只是一次
popup_but = (ImageView) findViewById(R.id.imageView2);
popup_but.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showmen();
}
});
和菜單:
public void showmen() {
PopupMenu popup = new PopupMenu(First.this, popup_but);
popup.getMenuInflater().inflate(R.menu.popup, popup.getMenu());
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId())
{
case R.id.men1:
//do something
return true;
case R.id.men5:
finish();
return true;
}
return true;
}
});
popup.show();
}
它。作品。現在我想在點擊硬件菜單按鈕時也這樣做。所以我用這個代碼:
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
showmen();
}
問題就在這裏:當菜單按鈕,點擊它只是顯示菜單首次