Question

i am using handler to show a slideshow of images. but i don't know how to pause the handler and then resume it back again. i can set onclicklistener on imageview but how to pause the handler in it:

class RefreshHandler extends Handler {
    @Override
    public void handleMessage(Message msg) {
        // TODO Auto-generated method stub
        TatSlideShow.this.updateUI();
    }

    public void sleep(long delayMillis) {
        this.removeMessages(0);
        sendMessageDelayed(obtainMessage(0), delayMillis);
    }
};

public void updateUI() {

    refreshHandler.sleep(3000);

    if ((count & 1) == 0) {
        refreshHandler.sleep(6000);
        tatslide.setImageResource(0);
        count++;
    } else {

        if (i < imgid.length) {
            tatslide.setImageResource(imgid[i]);

            // imageView.setPadding(left, top, right, bottom);
            i++;
            count++;
        }
    }

}
Était-ce utile?

La solution

Handler does not have a timer to tweak.

You can cancel posted Runnable's:

handler.removeCallbacks(yourCallback);

And post again, to resume.

Autres conseils

there is no pause. What you could do is to call removeCallbacks to remove the runnable and add it again, later, when your "pause" status finish.

Edit:

as @pskink pointed correctly out you are using messages. To remove messages you can call removeMessages()

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top