I have a ridiculous problem! I want to handle action home button, but MenuItem
passed to onOptionsItemSelected
method when i tap home button is not R.id.home
(nor R.id.homeAsUp
).
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
Log.v("1111", "MenuItem id: "+id);
Log.v("1111", "home id: "+R.id.home);
Log.v("1111", "homeAsUp id: "+R.id.homeAsUp);
...
}
Log:
11-19 23:58:56.433: V/1111(30059): MenuItem id: 16908332
11-19 23:58:56.433: V/1111(30059): home id: 2131296256
11-19 23:58:56.433: V/1111(30059): homeAsUp id: 2131296270
Any ideas?
You are missing the 'android' prefix. The Up button's id
is android.R.id.home
actually, not R.id.home
.
You handle home button like
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if(id==android.R.id.home){
/*Do your code here*/
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With