android 动态显示时间

作者: YuGoal | 来源:发表于2018-02-22 10:29 被阅读665次

是简单的实现一个动态显示时间的需求。使用RxJava


private Disposable subscription;
subscription = Observable.interval(0, 1, TimeUnit.SECONDS)
                .map(new Function<Long, Long>() {
                    @Override
                    public Long apply(Long aLong) throws Exception {
                        return aLong;
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<Long>() {
                    @Override
                    public void accept(Long aLong) throws Exception {
                        tvHour.setText(DateUtils.getHour(System.currentTimeMillis()));
                    }
                });

@Override
public void onDestroyView() {
        super.onDestroyView();
        if (!subscription.isDisposed()){
            subscription.dispose();
        }
    }

相关文章

网友评论

    本文标题:android 动态显示时间

    本文链接:https://www.haomeiwen.com/subject/pavatftx.html