Android: Update ListView Items every 1 minute

后端 未结 4 1518
长发绾君心
长发绾君心 2020-12-31 17:05

I have a Custom ListView in my application, containing an ImageView and 3-5 TextViews.

1 of the TextViews shows the time gap between the current time

4条回答
  •  無奈伤痛
    2020-12-31 17:46

    Use a Handler and its postDelayed method to invalidate the list's adapter as follows:

    final Handler handler = new Handler()
    handler.postDelayed( new Runnable() {
    
        @Override
        public void run() {
            adapter.notifyDataSetChanged();
            handler.postDelayed( this, 60 * 1000 );
        }
    }, 60 * 1000 );
    

    You must only update UI in the main (UI) thread.

    By creating the handler in the main thread, you ensure that everything you post to the handler is run in the main thread also.

提交回复
热议问题