Answering to my own question so that anybody else may happen this problem so here is a solution after trying to much.I have done it through a single condition by just checking that if the group has no child then it should set the white layout that will be shown as a white blank space and no other things like padding, dividers or margin needed. just like in the below code in getGroupView()
and you don't have to do anything else. The layout
(blank_white_layout
) I use is just a relativelayout
having white background
and you can give it height according to your needs.
if (getChildrenCount(groupPosition) == 0) {
view = inflater.inflate(R.layout.blank_white_layout, null);
}
and below is the complete getGroupView
code in my adapter class
public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
ViewGroup parent) {
if (groupPosition == 0 ) {
convertView = inflater.inflate(R.layout.group_layout1, null);
}
if (getChildrenCount(groupPosition) == 0) {
convertView = inflater.inflate(R.layout.blank_white_layout, null);
}else{
convertView = inflater.inflate(R.layout.group_layout2, null);
}
TextView text1 = (TextView) convertView.findViewById(android.R.id.text1);
return convertView;
}