java - Android how to add back button in activity to return back in fragment activity -


hello have simple activity , fragment want add add button on activity action bar , return fragment.here code

public class fragment2jazz extends fragment  {       button msgbutton;     button callbutton;     button internetbutton;      public fragment2jazz(){}      @override     public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {           view rootview = inflater.inflate(r.layout.jazz_fragment, container, false);          msgbutton = (button) rootview.findviewbyid(r.id.btnjazz1);         callbutton= (button) rootview.findviewbyid(r.id.btnjazz2);         internetbutton= (button) rootview.findviewbyid(r.id.btnjazz3);          msgbutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  intent intent = new intent(getactivity() , jazzmessage.class );                  getactivity().startactivity(intent);              }         });          callbutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  intent intent = new intent(getactivity() , jazzcall.class );                  getactivity().startactivity(intent);              }         });          internetbutton.setonclicklistener(new view.onclicklistener() {             @override             public void onclick(view view) {                  intent intent = new intent(getactivity() , jazzinternet.class );                  getactivity().startactivity(intent);              }         });          return rootview;     } } 

activity

public class jazzcall extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.jazz_detail_call);          actionbar actionbar = getactionbar();         actionbar.setbackgrounddrawable(new colordrawable(color.parsecolor("#ff9999")));      }  } 

change jazzcall following :

public class jazzcall extends activity {      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.jazz_detail_call);          actionbar actionbar = getactionbar();         actionbar.setbackgrounddrawable(new colordrawable(color.parsecolor("#ff9999")));          actionbar.setdisplayhomeasupenabled(true);         actionbar.setdisplayshowhomeenabled(true);      }      public boolean onoptionsitemselected(menuitem item) {         switch (item.getitemid()) {             case android.r.id.home:                 finish();                 return true;        }         return super.onoptionsitemselected(item);    } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -