Android-定期更新TextView [英] Android - Update TextView periodically

查看:73
本文介绍了Android-定期更新TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想通过服务定期更新TextView.假设TextView应该显示时间并每30秒更新一次.你们不能告诉我我怎么能做到吗?我知道我需要一个接收器,但是我尝试的所有操作都根本不起作用.

I simply want to update a TextView periodically by a service. Let's say the TextView should display the time and update itself every 30 seconds. Could't you guys tell me how I can achieve that? I know that I need a receiver for that but everything I tried did't work at all.

我是android的新手,也许您可​​以保持它简单:D

I'm new to android, maybe you can keep it simple :D

推荐答案

在onCreate()//每30秒更新一次

In onCreate() //updating every 30 seconds

      Handler handler =new Handler();
      final Runnable r = new Runnable() {
                public void run() {
                    handler.postDelayed(this, 30000);
                    String mydate = java.text.DateFormat.getDateTimeInstance().format(Calendar.getInstance().getTime());
                    edittextId.setText(mydate);
                }
            };
            handler.postDelayed(r, 0000);

这篇关于Android-定期更新TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆