i have this code in my main activity
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId == R.id.menu_edit) {
CharSequence title = item.getTitle();
Log.d("onOptionsItemSelected", "menu_edit title=" + title);
if(title=="Edit") {
// switch to RUn
item.setTitle("Run");
} else {
// switch to Edit
item.setTitle("Edit");
}
}
return super.onOptionsItemSelected(item);
}
the button is define like this
android:id="@+id/menu_edit"
android:orderInCategory="102"
android:showAsAction="ifRoom|withText"
android:title="Edit"/>
the basic idea is the "Edit" button toggles to "Run" and back when pressed. it kind of works except for the first time i press it it does nothing, then it works ok: note this is a item on the action bar, not in the menu so i don't think onPrepareOptionsMenu helps since its not called when pressing buttons on the action bar.
can someone suggest a way to get the first click to for setTitle to work?
thanks