java - Calling a variable or method in the activity class from a class that extends view? -
i new android , need help.
i have got gameactivity class , set setcontentview gameview class. want access variable located in gameview class gameactivity class.
is possible?
public class gameactivity extends activity { @override protected void oncreate(bundle savedinstancestate){ super.oncreate(savedinstancestate); view gameview = new gameview(this); setcontentview(gameview); } }
and gameview class
public class gameview extends view { private static final string tag = null; // log.e private ball ball1; // ball1 private gamecontainer gamecontainer; // frame game private racket racket; // controller int viewwidth = 0; // width onchange int viewheight = 0; // height onchange private score score; // constructor public gameview(context context) { super(context); ball1 = new ball(color.green, 24, 10, 2); // colour, radius,speedx, speedy ball1.setballlocation(10, 5); // x, y of ball gamecontainer = new gamecontainer(color.gray); racket = new racket(color.black); score = new score(color.white); } @override public void ondraw(canvas canvas){ gamecontainer.container(1, 2, 100, 100); gamecontainer.display(canvas); ball1.drawball(canvas); ball1.moveball(gamecontainer); // check ball if out display alert box if (ball1.getendgame()){ log.e(tag, "end of game"); } } }
plain old java
conventions should work.
add getter/setter methods variables need access , use them values.
public int getheight(){ return viewheight; }
would not work
Comments
Post a Comment