30
Android應用程序使用庫項目來包含大部分應用程序代碼,因爲從核心源構建的應用程序有兩個版本。由於一個IntelliJ IDEA的更新(V11)我得到這個警告以下各個case語句:Android庫項目中的菜單項ID?
Resource IDs cannot be used in a switch statement in Android library modules
下面的代碼:
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_item_one: // Build error here
// Do stuff
return true;
case R.id.menu_item_two: // Build error here
// Do stuff
return true;
default:
return super.onOptionsItemSelected(item);
}
}
好了,如果我不能引用他們通過他們的ID,我怎麼引用他們?
我想一個解決辦法是動態創建的菜單項,但消除使用資源爲菜單的所有優點。這些錯誤似乎是說在庫項目中不能使用XML菜單定義? –