java - Android if statement onClick doing nothing -
i have android test app (because new android development) has couple of onclick
secrets in changes screen, in particular 2 won't work. have find , click first 1 gain access other. before added system, both of secrets worked , changes made no problems.
my goal prevent people triggering second method before triggering first one. when first 1 triggered, app allows second method triggered.
the relevant java code:
private boolean colorchangable = false; public void changesecret(view v) { button btn = (button) findviewbyid(r.id.button); btn.settext("your mind has been blown!"); btn.settextcolor(color.blue); colorchangable = true; } public void changecolor(view v) { if (colorchangable){ textview tw = (textview) findviewbyid(r.id.textview); tw.settextcolor(color.red); tw.settext("again, mind has been blown."); } }
and relevant xml code:
<textview android:id="@+id/textview" android:onclick="changecolor" /> <button android:id="@+id/button" android:onclick="changesecret" />
what wrong code , there can improve?
p.s. cut useless parts in code, if there else important needed answer question, please notify me.
p.p.s. different other questions onclick not firing because in problem, onclick fires without boolean confirmation
second method changecolor
is being executed without needing of executing first method changesecret
. note if (colorchangable)
. line avoids rest of method executed when colorchangeable
variable false
default:
private boolean colorchangable = false;
so false until first method changesecret
executed...
i recommend add else see happening or explain want achieve in each case:
public void changecolor(view v) { textview tw = (textview) findviewbyid(r.id.textview); if (colorchangable){ tw.settextcolor(color.red); tw.settext("again, mind has been blown."); } else { tw.settext("you cannot change color."); }
Comments
Post a Comment