The Expandablelistview Adapter Child Not Updated On Runtime By Calling Notifydatasetchange
There is a button on BaseExpandableListAdapter on group view for adding comments in its child. When adding the item to the list and called notifyDataSetChanged() inside that adapte
Solution 1:
Can you please try to refresh adapter like
getActivity().runOnUiThread(new Runnable() {
publicvoidrun() {
this.notifyDataSetChanged();
}
});
Solution 2:
Actually, in my case, the height of expandableListView is not updated so it causes a problem on runtime. After digging into code. I call this setListViewHeight function after notifyDataSetChanged(), makes my expendable list view updated on runtime. I set the Height of my expandablelistView as:
publicstaticvoidsetListViewHeight(ExpandableListView listView, intgroup) {
ExpandableListAdapter listAdapter = (ExpandableListAdapter) listView.getExpandableListAdapter();
int totalHeight = 0;
int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(),
View.MeasureSpec.EXACTLY);
for (int i = 0; i < listAdapter.getGroupCount(); i++) {
View groupItem = listAdapter.getGroupView(i, false, null, listView);
groupItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += groupItem.getMeasuredHeight();
if (((listView.isGroupExpanded(i)) && (i != group)) || ((!listView.isGroupExpanded(i)) && (i == group))) {
for (int j = 0; j < listAdapter.getChildrenCount(i); j++) {
View listItem = listAdapter.getChildView(i, j, false, null,
listView);
listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
totalHeight += listItem.getMeasuredHeight()+1;
}
}
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
int height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getGroupCount() - 1));
if (height < 10)
height = 200;
params.height = height;
listView.setLayoutParams(params);
listView.requestLayout();
}
Post a Comment for "The Expandablelistview Adapter Child Not Updated On Runtime By Calling Notifydatasetchange"