java - how to make CountDown timer without button -
i'm making quiz app , need make countdown timer time question can answered, don't know how make countdown timer without pressing button or make countdown timer pressing button button on different layout. so, want ask how make countdown timer without button or how make count down timer button different layout count down timer?
**this code count down button in other layout still failed**
the id = mulai button other layout
the id = waktu textview count down timer in it's layout
public class tes1 extends appcompatactivity { checkbox cb1, cb2, cb3; int nilai = 0; private alertdialog.builder alertdialogbuilder; textview time; private button start; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_tes1); start = (button) findviewbyid(r.id.mulai); time = (textview) findviewbyid(r.id.waktu); start.setonclicklistener(new view.onclicklistener(){ public void onclick(view arg0){ countdowntimer count = new countdowntimer(15 * 1000, 1000) { @override public void ontick(long l) { time.settext("" + l/1000); } @override public void onfinish() { time.settext("times up"); } }.start(); } }); alertdialogbuilder = new alertdialog.builder(this); cb1 = (checkbox) findviewbyid(r.id.checkbox1); cb2 = (checkbox) findviewbyid(r.id.checkbox2); cb3 = (checkbox) findviewbyid(r.id.checkbox3); } public void nextbutton(view view) { boolean checkbox1 = cb1.ischecked(); boolean checkbox2 = cb2.ischecked(); boolean checkbox3 = cb3.ischecked(); int tambah = hitungnilaicheckbox(checkbox1, checkbox2, checkbox3); intent intent = new intent(getapplicationcontext(), tes2.class); intent.putextra("lempar_1", nilai); startactivity(intent); } private int hitungnilaicheckbox(boolean checkbox1, boolean checkbox2, boolean checkbox3) { if (checkbox1) { nilai = nilai + 3; } if (checkbox2) { nilai = nilai + 2; } if (checkbox3) { nilai = nilai + 1; } return nilai; } public void onbackpressed() { alertdialogbuilder.settitle("tidak diperbolehkan"); alertdialogbuilder.setmessage("anda sedang di dalam tes") .setnegativebutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialoginterface, int i) { dialoginterface.cancel(); } }).create().show(); }
}
@override protected void onstart() { super.onstart(); toast.maketext(getapplicationcontext(),"replace delicious medium-brown toast call timer", toast.length_long).show(); // }
Comments
Post a Comment