android - how to set set max counter and change TextView if max value is reached -
if value of counter more maxcount textview change. code. hope understand mean. thx.
int counter = 0; int maxcount = 5; textview txtcount, txtresult; private vibrator mvibrator; protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.tasbih); img = (imageview) findviewbyid(r.id.img_btn); img.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { mvibrator.vibrate(700); counter ++; txtcount.settext(integer.tostring(counter)); (int = 0; < maxcount; i++ ){ if (counter >= maxcount) { txtresult.settext("text 2"); counter = 0; break; }else if (counter >= maxcount){ txtresult.settext("text 3"); toast.maketext(mainactivity.class, "done!!!", toast.length_short).show(); } } }
consider using while loop
basically remove loop , place condition
while(counter <= maxcounter) { //your code set textview value counter++; //incrementing counter value in each loop }
Comments
Post a Comment