Reputation: 6072
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
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
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
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