android - Navigation view handle back button on fragment -
hi need handle button on fragment. using navigation on mobile apps. question how handle button when open new fragment page?
i try using below code on new fragment.
actionbar.setdisplayshowhomeenabled(true); actionbar.setdisplayhomeasupenabled(true);
but when click button , navigation open. solution ?
thanks
as know whenever user presses back
button need go loaded fragment , try (note fragment must added transaction.addtobackstack(null);
)
@override public boolean onoptionsitemselected(menuitem item) { if (item.getitemid() == android.r.id.home) { int backstackcount = fragmentmanager.getbackstackentrycount();//check how many frags loaded if (backstackcount > 0) { fragmentmanager.popbackstack(); //go loaded fragment } } return super.onoptionsitemselected(item); }
happycoding;
Comments
Post a Comment