java - Can I make a base class that I inherit this information from? -


my boss suggested me use inheritance classes in app. there 1 method use quite often, .this class changed.

here base code use:

public class currentclass extends appcompatactivity     implements navigationview.onnavigationitemselectedlistener {  @override  protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_currentclass);     toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);     setsupportactionbar(toolbar);      floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab);     fab.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view view) {             intent intent = new intent(currentclass.this, activitymenu.class);             startactivity(intent);         }     });      drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);     actionbardrawertoggle toggle = new actionbardrawertoggle(             this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close);     drawer.setdrawerlistener(toggle);     toggle.syncstate();      navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view);     navigationview.setnavigationitemselectedlistener(this);  }  @override  public void onbackpressed() {     drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);     if (drawer.isdraweropen(gravitycompat.start)) {         drawer.closedrawer(gravitycompat.start);     } else {         super.onbackpressed();     } }  @suppresswarnings("statementwithemptybody") @override public boolean onnavigationitemselected(menuitem item) {     int id = item.getitemid();      if (id == r.id.about) { //goes our company page         intent intent = new intent(currentclass.this, activityabout.class);         startactivity(intent);     }     else if (id == r.id.news) { // goes news , events page         intent intent = new intent(currentclass.this, activitynewsevents.class);         startactivity(intent);     }     else if (id == r.id.serve) { // markets serve         intent intent = new intent(currentclass.this, activitymarkets.class);         startactivity(intent);     }     else if (id == r.id.seta) { //seta , aquisition support         intent intent = new intent(currentclass.this, activityseta.class);         startactivity(intent);     }     else if (id == r.id.software) { //software , systems dev         intent intent = new intent(currentclass.this, activitysoftware.class);         startactivity(intent);     }     else if (id == r.id.training) { //intelligence analytics , training         intent intent = new intent(currentclass.this, activityanalytics.class);         startactivity(intent);     }     else if (id == r.id.qacstuff) { //qac         intent intent = new intent(currentclass.this, activityqac.class);         startactivity(intent);     }     else if (id == r.id.careers) { //careers         intent intent = new intent(currentclass.this, activitycareers.class);         startactivity(intent);     }     else if (id == r.id.contactus) { //contact         intent intent = new intent(currentclass.this, activitycontact.class);         startactivity(intent);     }      drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);     drawer.closedrawer(gravitycompat.start);     return true;     }  } 

i use in majority of classes, change currentclass whatever class copy into. so, question is, can make class inherit can use these methods without copy/pasting them every class? , if so, have resources/advice how that?

okay, clarification. have 15+ classes in android app have same base code, except changed. in code, wherever says "currentclass" change "activitymain" or "activitydevelopment" or whatever activity is. wondering if there more efficient way implement this, possibly using inheritance or calling these methods in other classes, without having copy/paste code.

you can create baseactivity(parent class activity) , extend class in activity create 1 method swith case, , call in onnavigationitemselected methods


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -