Android - Update TextView periodically

前端 未结 2 503
灰色年华
灰色年华 2021-01-22 14:36

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-22 15:02

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

提交回复
热议问题