Hi, I am using TreeView
with ExpandableListView
. But I have some problems with the measures, which, unfortunately, I can not solve.
Here are the screenshots of the problem:


You can see that there are problems when measuring. While I'm new to Android, I really don't understand the onMeasure()
method. I have 1 ExpandableListView
and in it getChildView()
I return CustomExapndableListView
-s.
Here is the code:
ExpandableListAdapter:
public class ExpandableListAdapter extends BaseExpandableListAdapter { private Context context; private List<String> listDataHeader; private HashMap<String, List<String>> listDataChild; public ExpandableListAdapter (Context context, List<String> listDataHeader, HashMap<String, List<String>> listChildData) { this.context = context; this.listDataHeader = listDataHeader; this.listDataChild = listChildData; } @Override public int getGroupCount() { return this.listDataHeader.size(); } @Override public int getChildrenCount(int groupPosition) { return this.listDataChild.get(this.listDataHeader.get(groupPosition)).size(); } @Override public Object getGroup(int groupPosition) { return this.listDataHeader.get(groupPosition); } @Override public Object getChild(int groupPosition, int childPosition) { return this.listDataChild.get(this.listDataHeader.get(groupPosition)).get(childPosition); } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public boolean hasStableIds() { return false; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { String headerTitle = (String) getGroup(groupPosition); Log.i("Header: ", " " + headerTitle); if(convertView == null) { LayoutInflater infalInflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = infalInflater.inflate(R.layout.list_group, null); } TextView lblListHeader = (TextView) convertView.findViewById(R.id.lblListHeader); lblListHeader.setTypeface(null, Typeface.BOLD); lblListHeader.setText(headerTitle); return convertView; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { String childText = (String) getChild(groupPosition, childPosition); if(listDataChild.containsKey(childText)){ Log.i("Child", "" + childText); CustomExpandableListView explv = new CustomExpandableListView(context);
CustomExpandableListView:
public class CustomExpandableListView extends ExpandableListView { private static final int HEIGHT = 20; private int rows; public void setRows(int rows) { this.rows = rows; } public CustomExpandableListView(Context context) { super(context); } public CustomExpandableListView(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { heightMeasureSpec = MeasureSpec.makeMeasureSpec(500, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec);
What I want to do when I expand the view, I want all the children to be shown, and I can just scroll down the ListView
. Now some children are hidden under different children.
Thanks to Advance for your help.