资源ID在Android电子图书馆项目 [英] Resource ID In Android Library Project
问题描述
我想包括我的一个开源项目。但检查后,被库选项,有些东西像案R.id.menu_search:不能编译。我应与contant值替换他们,或者我怎么能有呢?
情况下R.id.menu_search://!案例前pressions必须恒定前pressions
onSearchRequested();
返回true; ...
正如其他人所指出的那样,你需要你的开关()
语句改为如果()
/ 否则,如果()
/ 其他
语句。 R.id.menu_search
不是一个常数(静态最后
),并不能在情况
语句。这是因为 R.id.menu_search
从你的Android库项目的到来。 android.R.id.home
的是的常数,因为这是操作系统的一部分,并没有改变。
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; ...
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.
这篇关于资源ID在Android电子图书馆项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!