문제

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++;
        }
    }

}
도움이 되었습니까?

해결책

Handler does not have a timer to tweak.

You can cancel posted Runnable's:

handler.removeCallbacks(yourCallback);

And post again, to resume.

다른 팁

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()

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top