So basically, I have an Activity that implements an interface and has several inherited functions. each of these function would be invoked and pass the data that will be used to update my List adapter. this is the snippet:
@Override
public void onEntriesAdded(List<String> addresses) throws RemoteException {
Log.v(TAG, "Entries Added notify!");
listEntriesAdd.clear();
listEntriesAdd = addresses;
rosterHandler.sendEmptyMessage(1);
}
@Override
public void onEntriesUpdated(List<String> addresses) throws RemoteException {
Log.v(TAG, "Entries Updated notify!");
listEntriesUpdate.clear();
listEntriesUpdate = addresses;
rosterHandler.sendEmptyMessage(2);
}
@Override
public void onEntriesDeleted(List<String> addresses) throws RemoteException {
Log.v(TAG, "onEntries deleted " + addresses);
listEntriesDel.clear();
listEntriesDel = addresses;
rosterHandler.sendEmptyMessage(3);
}
because I’ve seen any solutions before, I pass the the work for each function into a Handler:
private Handler rosterHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case 0:
// adding or any List<String> elements operations
break;
case 1:
// adding or any List<String> elements operations
break;
case 2:
// adding or any List<String> elements operations
break;
case 3:
// adding or any List<String> elements operations
break;
case 4:
// adding or any List<String> elements operations
break;
}
mAdapterContact.notifyDataSetChanged();
}
};
and then, there’s a ServiceConnection class that would be called when I execute bindService:
@Override
protected void onResume() {
super.onResume();
if (!mBinded) {
Log.d(TAG, "Request BIND Service");
mBinded = bindService(SERVICE_INTENT, mServConn, BIND_AUTO_CREATE);
}
}
and the Service class:
private class MyServiceConnection implements ServiceConnection {
public MyServiceConnection() {
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
globalBinder = service;
mXmppFacade = IXmppFacade.Stub.asInterface(service);
try {
mRoster = mXmppFacade.getRoster();
if (mRoster != null) {
Log.i(TAG, "REBUILD ROSTER!!!");
rosterHandler.sendEmptyMessage(0);// send it to handler
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
@Override
public void onServiceDisconnected(ComponentName name) {
try {
mRoster.removeRosterListener(ContactList.this);
} catch (RemoteException e) {
e.printStackTrace();
}
mXmppFacade = null;
mChatManager = null;
mRoster = null;
mListContact.clear();
mListGroup.clear();
mContactOnGroup.clear();
mBinded = false;
}
}
So as you can see, I currently updating my List actually, an expandable listview like this…
but everytime I get this error: Android, ListView IllegalStateException: “The content of the adapter has changed but ListView did not receive a notification”!
I really confused, I don’t know where to place these procedures properly to avoid this error and still can update my list 🙁
Please HELP!
Try to run
mAdapterContact.notifyDataSetChanged();on UI thread (Activity.RunOnUIThread), and double checkmAdapterContactis real list adapter.Also, try to call
notifyDataSetChanged()right aftersetAdapter()