Gaurav Arora Gaurav Arora - 4 months ago 15
Android Question

Expandable List Adapter is not refreshing at all

I am using one expandable list and it shows the presence of the users in the chatting ( at run time) whenever there is a change in the presence of the user, i am sending a broadcast to refresh the adapter but it is not refreshing at all.

here is the code

to set the adapter

/** Set Adapter here */
adapter = new UserMenuAdapter(this, groupNames, childs);
setListAdapter(adapter);
object = this;


I call this receiver from a service using sendbroadcast method, and I have already checked that its onReceive but the list is not refreshing.

BroadcastReceiver UpdateList = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {

groupChileItem();
adapter.notifyDataSetChanged();

}
};


//groupChileitem ( method )

private void groupChileItem(){
/***###############GROUP ARRAY ############################*/
final ArrayList<String> groupNames = new ArrayList<String>();

if(XMPPConn.mfriendRequestList.size() > 0){
groupNames.add("Request ("+XMPPConn.mfriendRequestList.size()+")");
}else{
groupNames.add("Request (0)");
}
chatUser = dbHelper.getChatUser();
groupNames.add("Chats ("+chatUser.size()+")");
groupNames.add("Contacts (" + XMPPConn.mfriendList.size() + ")");
groupNames.add("CGM Groups (" + XMPPConn.mGroupList.size() + ")");
if(XMPPConn.mfriendPendingList.size() > 0){
groupNames.add("Pending ("+XMPPConn.mfriendPendingList.size()+")");
}else{
groupNames.add("Pending (0)");
}

mXMPPConn.getGroup();
categoryList = dbHelper.getAllCategory();
/**Group From Sever*/
if (XMPPConn.mGroupList.size() > 0) {
for (int g = 0; g < XMPPConn.mGroupList.size(); g++) {
mXMPPConn.getGroupContact(XMPPConn.mGroupList.get(g).groupName);
groupNames.add(XMPPConn.mGroupList.get(g).groupName + "("
+ XMPPConn.mGroupContactList.size()+ ")");
}
}
this.groupNames = groupNames;

/*** ###########CHILD ARRAY * #################*/
ArrayList<ArrayList<ChildItems>> childs = new ArrayList<ArrayList<ChildItems>>();
ArrayList<ChildItems> child = new ArrayList<ChildItems>();
/**child for request frieds*/
if(XMPPConn.mfriendRequestList.size() > 0){
for(int i = 0; i < XMPPConn.mfriendRequestList.size(); i++){
child.add(new ChildItems(XMPPConn.mfriendRequestList.get(i).friendNickName,
"Waiting for Authorization",0,null));
}
}else{
child.add(new ChildItems("No Request list","",0,null));
}
childs.add(child);
/**Child for chat */
child = new ArrayList<ChildItems>();
if(chatUser.size() > 0){
for(int i = 0; i < chatUser.size(); i++){
child.add(new ChildItems(userName(chatUser.get(i)), "",0,null));
}
}else{
child.add(new ChildItems("--No History--", "",0,null));
}
childs.add(child);
/**Child for contact list*/
child = new ArrayList<ChildItems>();
child.add(new ChildItems("", "",0,null));
if (XMPPConn.mfriendList.size() > 0) {
for (int n = 0; n < XMPPConn.mfriendList.size(); n++) {
child.add(new ChildItems(XMPPConn.mfriendList.get(n).friendNickName,
XMPPConn.mfriendList.get(n).friendStatus,
XMPPConn.mfriendList.get(n).friendState,
XMPPConn.mfriendList.get(n).friendPic));
}
}
childs.add(child);
/************** CGM Group Child here *********************/
child = new ArrayList<ChildItems>();
child.add(new ChildItems("", "",0,null));

if (XMPPConn.mGroupList.size() > 0) {
for (int grop = 0; grop < XMPPConn.mGroupList.size(); grop++) {
child.add(new ChildItems(
XMPPConn.mGroupList.get(grop).groupName + " ("
+ XMPPConn.mGroupList.get(grop).groupUserCount
+ ")", "",0,null));
}
}
childs.add(child);

/**Pending friend*/
child = new ArrayList<ChildItems>();
if(XMPPConn.mfriendPendingList.size()> 0){
for(int i = 0; i < XMPPConn.mfriendPendingList.size(); i++){
child.add(new ChildItems(XMPPConn.mfriendPendingList.get(i).friendNickName,
"Waiting for Authorization",0,null));
}
}else{
child.add(new ChildItems("No Pending list","",0,null));
}
childs.add(child);
/************************ Group Contact List *************************/
if (XMPPConn.mGroupList.size() > 0) {
for (int g = 0; g < XMPPConn.mGroupList.size(); g++) {
/** Contact List */
mXMPPConn.getGroupContact(XMPPConn.mGroupList.get(g).groupName);
child = new ArrayList<ChildItems>();
for (int con = 0; con < XMPPConn.mGroupContactList.size(); con++) {
child.add(new ChildItems(
XMPPConn.mGroupContactList.get(con).friendNickName,
XMPPConn.mGroupContactList.get(con).friendStatus,0,null));
}
childs.add(child);
}
}
this.childs = childs;

}


Anybody please tell me what I am doing wrong?

Answer

I would insist you to try setting the Adapter again instead of using notifyDataSetChanged()

so you can try using,

setListAdapter(adapter);

intead of using,

adapter.notifyDataSetChanged();
Comments