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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -