资源ID在Android电子图书馆项目 [英] Resource ID In Android Library Project

查看:149
本文介绍了资源ID在Android电子图书馆项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想包括我的一个开源项目。但检查后,被库选项,有些东西像案R.id.menu_search:不能编译。我应与contant值替换他们,或者我怎么能有呢?

 情况下R.id.menu_search://!案例前pressions必须恒定前pressions
        onSearchRequested();
        返回true; ...


解决方案

正如其他人所指出的那样,你需要你的开关()语句改为如果() / 否则,如果() / 其他语句。 R.id.menu_search 不是一个常数(静态最后),并不能在情况语句。这是因为 R.id.menu_search 从你的Andr​​oid库项目的到来。 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆