java - Button not updating its text -
i'm working android game. when application start show button ("start") start game. when user lose, application should show original view , changing button text "restart". when start application works fine when user lose original view (button text not changed) , button not responding. have 2 classes : gameactivity , gameview : in gameactivity have :
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); init(); } public void init() { setcontentview(r.layout.activity_catch_game); fruitview = (catchgameview) findviewbyid(r.id.l3infocatchgameview1); fruitview.setactivity(this); if (bstart == null) { //when launch app bstart = (button) findviewbyid(r.id.start); bstart.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { buttonstartclickeventhandler(); } }); } else{ bstart.settext("restart"); } }
in gameview have :
private void showscore() { stoptimer(); alertdialog.builder popupbuilder = new alertdialog.builder( this.getcontext()); textview message = new textview(this.getcontext()); message.settext("score : " + score); message.setgravity(gravity.center_horizontal); popupbuilder.setview(message); popupbuilder.setcancelable(true); popupbuilder.setneutralbutton("ok", new dialoginterface.onclicklistener() { public void onclick(dialoginterface dialog, int id) { dialog.cancel(); invalidate(); activity.init(); } }); popupbuilder.show(); }
when debug see instruction change button text executed.
the problem init()
method calls setcontentview()
.
when this, activity's layout re-inflated. of references views (such bstart
) point views in old copy of layout, no longer visible user.
since bstart
still referencing though, if (bstart == null)
false , don't updated reference bstart
.
i move separate logic updating button's text logic setting activity's layout.
Comments
Post a Comment