Using two different layouts for child items in ExpandableListView

前端 未结 2 1469
暖寄归人
暖寄归人 2020-12-20 14:39

I\'m trying to do the ExpandableListView to use two different layouts depending on item type. At this time I made basic functionality except one thing: after se

相关标签:
2条回答
  • 2020-12-20 14:56

    I'm pretty sure that you are not returning the good child values when convertView != null on your getChildView method. Try to set your values after your condition, like that :

    TextView textView = null;
    
    if (convertView == null) {
         LayoutInflater inflater = (LayoutInflater)getSystemService(getBaseContext().LAYOUT_INFLATER_SERVICE);
         int itemType = getChildType(groupPosition,childPosition);
         String myText = childData.get(groupPosition).get(childPosition).get("chapter");
    
         switch (itemType) {
             case 0:
                 convertView = inflater.inflate(com.oleg.mart.foreign.R.layout.child_row_notlast, null);
                 break;
             case 1:
                 convertView = inflater.inflate(com.oleg.mart.foreign.R.layout.child_row, null);
                 break;
        }
    }
    
    textView = (TextView)convertView.findViewById(com.oleg.mart.foreign.R.id.NChild);
    textView.setPadding(30,20,30,20);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
    textView.setText(Html.fromHtml(myText));
    

    If you still have a problem with that, please put a comment on my answer to tell me and I will see what I can do.

    0 讨论(0)
  • 2020-12-20 14:59

    Use HeterogeneousExpandableList . (https://developer.android.com/reference/android/widget/HeterogeneousExpandableList.html) It provides feature to have different header/child views in expandable list view.and also maintains its reuse.

    0 讨论(0)
提交回复
热议问题