Hardik Trivedi
Hardik Trivedi

Reputation: 6072

Refresh ListView items on every second

Say I have data coming from server or local database. I am displaying them in listview. I have four-five textview in each listview item.Now I want to refresh listview item every second (requirement is something like this only).

How should I achieve this. notifyDataSetChanged() is I am aware about.

I want some robust solution which does not make the activity laggy.

Please guide.

Upvotes: 2

Views: 3481

Answers (3)

Dhruvil Patel
Dhruvil Patel

Reputation: 2930

 private Thread t;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);



        t = new Thread(){   
            @Override
            public void run() {
                try {
                    synchronized(this){ 
                        wait(2000); // set time whatever you want
                    }


                } 
                catch(InterruptedException ex){ 
                    ex.printStackTrace();
                }

               lv.clear();
               onCreate(null);
            }
        };
            t.start();
    }

try this ..

Upvotes: 1

Mufazzal
Mufazzal

Reputation: 81

I think you should decrease your updating frequency. 1 second is too small for updates. You can use AsyncTask Execute this in every 1 sec. with the help of postDelay()

Upvotes: 1

Changwei Yao
Changwei Yao

Reputation: 13101

I think use notifyDataSetChanged is the only way to do it.

Why do you think it may make the Activity laggy?

Upvotes: 1

Related Questions