gigs gigs - 4 months ago 63
Android Question

Android - update custom listview every minute in real time

I know that in order to update Listview I have to use

notifyDataSetChanged()
. But, how can I update custom Listview every minute in real time?

For example, my app has created Listview at 05h:10m:20s and after 40 seconds it should updates Listview every one minute. In other words it should determines if current time have changed by one minute and than update Listview. How can I achieve that?

Answer

I suppose you want to update your ListView every minute at second 0. If not, you should use other answers.

If so, you can try register broadcast receiver for ACTION_TIME_TICK.

IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_TIME_TICK);

Context.registerReceiver(new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        adapter.notifyDataSetChanged();
    }
}, intentFilter);

Do not forget to call Context.unregisterReceiver() at onStop() of your Activity

Comments