android accessing resources in menu folder
-
28-10-2019 - |
سؤال
i'm using actionbarsherlock and i declared my menu in actionbar.xml in the menu folder. here's the content of actionbar.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/abSearch" android:showAsAction="always" android:icon="@drawable/search_orange"></item>
</menu>
now i tried to implement onOptionsItemSelected and here's what I did:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.abSearch:
Intent intent = new Intent(this, SearchRecipes.class);
startActivity(intent);
return true;
}
}
but the problem is eclipse says abSearch cannot be resolved. I tried cleaning the projects many times but to no avail.
المحلول
Replace:
android.R.id.abSearch
With:
R.id.abSearch
لا تنتمي إلى StackOverflow