@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) this.findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
PopupMenu poMenu = new PopupMenu(MainActivity.this, v);
poMenu.setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case R.id.action_add:
Toast.makeText(MainActivity.this, "添加被点击", 1).show();
break;
case R.id.action_delete:
Toast.makeText(MainActivity.this, "添加被点击", 1).show();
break;
default:
break;
}
return false;
}
});
MenuInflater inflater = poMenu.getMenuInflater();
inflater.inflate(R.menu.main, poMenu.getMenu());
poMenu.show();
}
});
}