原文地址:http://blog.csdn.net/wchinaw/article/details/7325641
在一般的Android项目里R里面的资源声明看起来是这样的:
public static final int ...
但是在ADT14之后,声明是这样的
public static int ..
所有case语句换成if 就可以了
Non-constant Fields in Case Labels
In a regular Android project, constants in the resource R class are declared like this: public static final int main=0x7f030004; However, as of ADT 14, in a library project, they will be declared like this: public static int main=0x7f030004; In other words, the constants are not final in a The reason the fields are no longer final is that it means that the However, it has one impact on the source code of the library. Code of the following form will no longer compile: int id = view.getId(); switch (id) { case R.id.button1:
That‘s because the The solution for this is simple: Convert the switch statement into In the above scenario, it will turn the int id = view.getId(); if (id == R.id.button1) { action1(); } else if (id == R.id.button2) { action2(); } else if (id == R.id.button3) { action3(); } This is typically in UI code and the performance impact is negligible. We have a detector which finds these errors (non-constant case More information about the automatic detection. P.S. If your switch statement looks like this: then you end up with an inefficient |