java.lang.IllegalStateException: The content of the adapter has changed but ListView.... inspite of calling notifydatasetchanged()
Posted
by
Mistaken
on Stack Overflow
See other posts from Stack Overflow
or by Mistaken
Published on 2012-10-19T16:38:54Z
Indexed on
2012/10/19
17:01 UTC
Read the original article
Hit count: 175
What are the best practices to be followed to update the contents of a listactivty by a background thread (Async Task) ?
1) Am calling the notifyDataSetChanged() to update the adapter as soon as i manipulate the contents of the adapter but still my app force closes while the user scrolls or click on the list. Any pointers to prevent this would be very helpfull.
Logcat: java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification.
2) Where exaclty should i update contents of the listactivity ? inside the doInBackground() or onProgressUpdate()?
3) Am experiencing regular crashes when the user clicks the list item. So will disabling click events on the listactivty during the background operation solve the problem ? If so am not sure how to remove or set item click listeners dynamically to the listactivity. Please instruct me on the too.
4) I dont think blocking all ui interactions during the background async task execution is the only way to solve the problem. I know there is a simple way of doing this but need some help.
Thanks in advance.
This is my onCreate...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fa);
tvStatus=(TextView) findViewById(R.id.tvStatus);
adapter = new SimpleAdapter(
this,
mostPopularList,
R.layout.list_item,
new String[] {"title","author","views","date"},
new int[] {R.id.textView1,R.id.textView2,R.id.textView4,R.id.textView3});
//populateList();
setListAdapter(adapter);
}
My async task...
private class LongOperation extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... params) {
// code for adding new listactivty items
}
@Override
protected void onPostExecute(String networkStatus) {
adapter.notifyDataSetChanged();
}
@Override
protected void onPreExecute() {
}
@Override
protected void onProgressUpdate(Void... values) {
}
}
© Stack Overflow or respective owner