android 动态显示时间

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


private Disposable subscription;
subscription = Observable.interval(0, 1, TimeUnit.SECONDS)
                .map(new Function() {
                    @Override
                    public Long apply(Long aLong) throws Exception {
                        return aLong;
                    }
                })
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer() {
                    @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 动态显示时间)