Resource ID In Android Library Project

自闭症网瘾萝莉.ら 提交于 2019-11-30 17:25:18

问题


I wanna include an open-source project in mine. But after check the "is library" option, some thing like "case R.id.menu_search:" can't be compiled. Should I replace them with its contant values, or how can I include it?

    case R.id.menu_search: // ! case expressions must be constant expressions
        onSearchRequested();
        return true; ...

回答1:


As others have pointed out, you need to change your switch() statement to if()/else if()/else statements. R.id.menu_search is not a constant (static final) and cannot be used in a case statement. That is because R.id.menu_search is coming from your Android library project. android.R.id.home is a constant, because that is part of the OS and is not changing.



来源:https://stackoverflow.com/questions/12475166/resource-id-in-android-library-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!