gpt4 book ai didi

java - 我如何实现setonmenuitemclicklistener?

转载 作者:太空宇宙 更新时间:2023-11-04 15:08:49 24 4
gpt4 key购买 nike

我正在尝试以下代码

@Override
public boolean onOptionsItemSelected(MenuItem item){

// same as using a normal menu

switch(item.getItemId()) {

case R.id.refresh_acti:
MenuItem it = (MenuItem) findViewById(R.id.refresh_acti);
it.setOnMenuItemClickListener(new OnMenuItemClickListener() {

@Override
public boolean onMenuItemClick(MenuItem item) {
// TODO Auto-generated method stub
return false;
}
});

// makeToast("Refreshing...");

break;

case R.id.setting_lay:

makeToast("Saving...");

break;

}



return true;

}

但是... it.setonmenuitemclicklistner 给出以下错误。

The method setOnMenuItemClickListener(MenuItem.OnMenuItemClickListener) in the type MenuItem is not applicable for the arguments (new
OnMenuItemClickListener(){})

最佳答案

你尝试过这个吗:

 public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case id_1:
Log.d("Log","ID 1 PRESSED");
return true;
default:
return super.onOptionsItemSelected(item);
}
}

关于java - 我如何实现setonmenuitemclicklistener?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21613209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com