Mick
Mick

Reputation: 1219

How to refresh the listview content in timely manner

Hello I want to refresh the list view in timely manner, Here I am not adding/deleting any rows. I want to refresh because to refresh existing data in a rows.

I am doing this but this is not working for me.

// Update the Message on the screen to help for troubleshooting.
private void updateListView() {
    // Callback to update the message in a second.
    new CountDownTimer(30000, 1000) {

        @Override
        public void onTick(long arg0) {
            adapter.notifyDataSetChanged();
            listView.invalidateViews();
            listView.refreshDrawableState();
        }

        @Override
        public void onFinish() {

        }
    }.start();
}

Upvotes: 0

Views: 121

Answers (1)

android developer
android developer

Reputation: 116060

just use a handler and notifyDataSetChanged:

    final Handler handler = new Handler();
    final int REFRESH_EVERY_X_MS = 1000;
    handler.postDelayed(new Runnable() {

        @Override
        public void run() {
            mAdapter.notifyDataSetChanged();
            handler.postDelayed(this, REFRESH_EVERY_X_MS);
        }
    }, REFRESH_EVERY_X_MS);

and in case you wish to stop (and you should), use handler.removeCallbacks and set the exact same runnable as the parameter.

Upvotes: 2

Related Questions