简体   繁体   English

Android:ActionBar菜单项无法解析或不是字段

[英]Android : ActionBar menu item cannot be resolved or isn't a field

I've got a ActionBar in my application. 我的应用程序中有一个ActionBar。 I can see it, click on the item etc. But I can't do anything because the program doesn't recognize the item in my onOptionsItemSelected function. 我可以看到它,点击项目等。但我无法做任何事情,因为程序无法识别我的onOptionsItemSelected函数中的项目。

public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case android.R.id.create_playlist:
        // ...
        return true;

        default : return super.onOptionsItemSelected(item);
        }
}

The item create_playlist gives me this error : 项目create_playlist给了我这个错误:

create_playlist cannot be resolved or is not a field create_playlist无法解析或不是字段

Yet this item is defined in my actionbar_menu.xml, with this id. 然而,这个项目在我的actionbar_menu.xml中定义,带有此id。 Tutorials I've found on the web use the same method and seem to work. 我在网上找到的教程使用相同的方法,似乎工作。 Does anyone know what could be happening here? 有谁知道这里会发生什么?

android.R.id.create_playlist

不应该只是R.id.create_playlist (没有android.前缀)?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM