请原谅我,但我只是android编程的初学者!我想制作一个弹出菜单,点击一个项目后我想调用die public void function RefreshMenuItems(2);但没有任何反应。我希望有人可以告诉我如何从主要活动中调用函数
这是我的代码:
/**
* A Button that acts as the view element for the popup menu.
*/
final Button btn = (Button) findViewById(R.id.btn_click);
/**
* Step 1: Create a new instance of popup menu
*/
final PopupMenu popupMenu = new PopupMenu(this, btn);
/**
* Step 2: Inflate the menu resource. Here the menu resource is
* defined in the res/menu project folder
*/
popupMenu.inflate(R.menu.popup_menu);
/**
* Step 3: Call show() method on the popup menu to display the
* menu when the button is clicked.
*/
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
popupMenu.show();
}
});
/**
* Handle menu item clicks
*/
popupMenu.setOnMenuItemClickListener(
new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_red:
// Here i want to call the function but nothing happens ??
RefreshMenuItems(2);
return true;
case R.id.menu_blue:
btn.setBackgroundColor(0xfff00000);
break;
case R.id.menu_green:
btn.setBackgroundColor(0xfff00000);
break;
}
return true;
}
}
);