I have stared my eyes red on this:
I use ABS and everything works perfectly under Android 2.2, but on ICS item.getItemId()
always returns 0. Since item.toString()
returns different values. I feel I should be able to solve this, but I alway end up on the Info-page.
public boolean onCreateOptionsMenu(Menu menu) {
menu.add("Info")
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
menu.add("Preferences")
.setIcon(R.drawable.ic_preferences)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if(item.toString() == "Preferences"){
Intent intent = new Intent();
intent.setClass(this,Preferences.class);
startActivity(intent);
return true;
}
else {
Intent intent = new Intent();
intent.setClass(this,Info.class);
startActivity(intent);
return true;
}
}
I guess I should switch on item.getItemId()
instead, but I can't figure out where to define the ActionBar Views. For some time I have puzzled with a file actionbar.xml under the menu folder, but with little success:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/preferences"
android:showAsAction="always"
android:icon="@drawable/ic_preferences"></item>
<item android:id="@+id/info"
android:showAsAction="always"></item>
</menu>
One should believe the the answer is rather simple. Can anyone give me a point in the right direction on an approach that works the same from SDK version 7 throught 15?
Any help is greatly appreciated.