Resource ID in Android Library Project

I want to include an open source project in mine. But after checking the "is a library" option, some thing like "case R.id.menu_search:" cannot be compiled. Should I replace them with my constant values ​​or how to enable it?

case R.id.menu_search: // ! case expressions must be constant expressions onSearchRequested(); return true; ... 
+4
source share
1 answer

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

+13
source

Source: https://habr.com/ru/post/1434818/


All Articles