android - simulate onOptionsItemSelected inside method call -
i have imageview inside xml layout. imageview has onclick method.
android:onclick="onhomeclicked"
when user clicks image, want in turn call onoptionsitemselected
inside activity. how that?
the following code gives null homemenuitem
:
menuitem homemenuitem; @override public boolean onprepareoptionsmenu(menu menu) { homemenuitem = menu.finditem(android.r.id.home); super.onprepareoptionsmenu(menu); return true; } public void onhomeclicked(view view) { onoptionsitemselected(homemenuitem); }
possible have declare method , call onoptionsitemselected
, onhomeclicked
onoptionsitemselected(menuitem item){ switch(item.getitemid()) { case r.id.btn: younewmethod(); break; } } public void onhomeclicked() { younewmethod(); } private void younewmethod(){ // write code here }
Comments
Post a Comment