简体   繁体   English

Java文本可更改计时器

[英]Java renewable timer for text change

I need to make a "typing..." implementation, which will change back to fe "online" status, unless renewed. 我需要进行“键入...”实施,除非重新进行更新,否则它将变回“在线”状态。 So, basically each time i get "typing" notification I want to set "typing" status for 2 seconds and then change it back, but if I get another "typing" notification, the countdown must reset. 因此,基本上,每次我收到“ typing”通知时,我都希望将“ typing”状态设置2秒钟,然后再将其更改回去,但是如果我收到另一个“ typing”通知,则必须重置倒数计时。 How can I achieve this? 我该如何实现? Thank you 谢谢

Thanks to @Amy I got the answer. 感谢@Amy,我得到了答案。 For those, who interested: 对于那些谁感兴趣:

First, create Handler and Runnable: 首先,创建Handler和Runnable:

    composingHandler = new Handler();
    composingRunnable = new Runnable() {
        @Override
        public void run() {
            setToolbarSubTitle(getString(R.string.online));
        }
    };

Then in code: 然后在代码中:

    setToolbarSubTitle(getString(R.string.typing));                              
    composingHandler.removeCallbacks(composingRunnable);
    composingHandler.postDelayed(composingRunnable, 2000);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM