Calling a group of methods from different classes in eclipse -


i'm new programming in eclipce android, , i'm little lost, i'm trying make application multiple screens, same menus, fact have created several classes , each class several methods, want include same methods in each class, can encapsulate group of methods 1 , call them different classes..

here methods repeated in each class

public void lanzarconfig(view view){       intent = new intent(this, config.class);    startactivity(i);     }  public void lanzarconsola(view view){       intent = new intent(this, consola.class);   startactivity(i);     }  public void lanzaracercade(view view){       intent = new intent(this, acercade.class);    startactivity(i);     }  public void lanzarsalir(view view){       intent = new intent(this, salir.class);   startactivity(i);     }  @override public boolean oncreateoptionsmenu(menu menu) {        super.oncreateoptionsmenu(menu);        menuinflater inflater = getmenuinflater();        inflater.inflate(r.menu.menu, menu);        return true;      }      @override public boolean onoptionsitemselected(menuitem item) {              switch (item.getitemid()) {               case r.id.acercade:                     lanzaracercade(null);                     break;               case r.id.config:                     lanzarconfig(null);                     break;               case r.id.consola:                     lanzarconsola(null);                     break;               case r.id.salir:                     lanzarsalir(null);                     break;               }              return true;      } 

how call them other classes without having copy entire code..?

save these methods in new class classname , use inheritance:

public class whateverclass extends classname 

every instance of class whateverclass can use methods of class classname.

read more inheritance here.


Comments

Popular posts from this blog

Java sticky instances of class com.mysql.jdbc.Field aggregating -