android - How to Increment a timer when a certain button is clicked? -


i know if it's possible increment seconds, hours, or minutes while timer running. have implemented answer in apps feedadapter. used kind of incremental function in countdowntimer , worked out!, when pause , resume again.(let's not it). handlers , functions in links's answer!

i have 2 button in adapter: 1: start's timer 2: want button increment seconds or minutes etc. appreciate gets through!

how handle multiple countdown timers in listview?

public void incrementexpirationtime () {         int defaultincrementvalue = 10000; //lets ten seconds (this can long data)        long productexpirytime = getproductexpirytime();        productexpirytime+=defaultincrementvalue; } 

i made private long productexpirytime; instance didn't help.

you can tinker better. how did take think useful let me know if have question.

private final int increment = 10; private final int one_second = 1; private boolean running = false; private int time = 100;  public void initialize() {     final button start = findviewbyid(r.id.start);     start.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             running = !running;             if (running)                 updatebutton(start);         }     });      final button increment = findviewbyid(r.id.increment);     increment.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             if (running)                 time += increment;         }     }); }  private void updatebutton(final button start) {     start.postdelayed(new runnable() {         @override         public void run() {             time--;             start.settext(string.valueof(time));             if (time == 0) {                 toast.maketext(getapplicationcontext(), "time up!", toast.length_short).show();                 running = false;             } else {                 if (running) {                     updatebutton(start);                 }             }         }     }, one_second); } 

Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -