Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resource ID In Android Library Project

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; ...
like image 695
thecr0w Avatar asked Sep 18 '12 10:09

thecr0w


1 Answers

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.

like image 119
CommonsWare Avatar answered Oct 19 '22 15:10

CommonsWare