Menu item call twice in fragment android -


in fragment when click on menu item , calls function twice 1 previous fragment , other 1 existing fragment.  fragment 1:      @override         public void onactivitycreated(bundle savedinstancestate) {             super.onactivitycreated(savedinstancestate);             sethasoptionsmenu(true);         }         @override         public boolean onoptionsitemselected(menuitem item) {             if(item.getitemid() == r.id.refresh){                 retrycallmap();                 return true;             }else             return false;         } fragment 2:      @override         public void onactivitycreated(bundle savedinstancestate) {             super.onactivitycreated(savedinstancestate);             sethasoptionsmenu(true);         }         @override         public boolean onoptionsitemselected(menuitem item) {             if(item.getitemid() == r.id.refresh){                 retrycall();                 return true;             }else             return false;         } mainactivity :      @override         public boolean oncreateoptionsmenu(menu menu) {             getmenuinflater().inflate(r.menu.menu_main, menu);             return true;         }          @override         public boolean onoptionsitemselected(menuitem item) {             int id = item.getitemid();             if (id == r.id.map) {                 pushfragments("mapfragment", new mapfragment(), true, true);                 return true;             }             if (id == android.r.id.home) {                 this.drawerlayout.opendrawer(drawablelistview);                 return true;             }             return super.onoptionsitemselected(item);         } 

these fragments , mainactivity refreshing fragment on menu item click if internet connection not found or other problem occurs while fetching can refresh page.

returning true in onoptionsitemselected() function worked me.

 @override     public boolean onoptionsitemselected(menuitem item) {         if(item.getitemid() == r.id.refresh){             retrycall();             return true;         }else         return true;     } 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -