当第二级是ExpandableList时,子视图不会扩展

时间:2016-07-04 07:39:23

标签: android expandablelistview expandablelistadapter

通过所有这些链接。

How to add Three Level ListView in ExpandableListView in android

http://twocentscode.blogspot.in/2014/02/three-level-expandable-listview.html

https://forums.xamarin.com/discussion/32342/expandablelistview-for-3-or-more-levels

  

父适配器代码。

public class ExpandableListAdapter extends BaseExpandableListAdapter {


private static final String TAG = ExpandableListAdapter.class.getSimpleName();
Context context;
ArrayList<ExpandParentData> group;

private TextView mTVHeader,mTVHeaderValue,mTVHeaderChild,mTVHeaderChildValue;



ExpandableListView expand_child_parent;

ExpandableChildAdapter expandableChildAdapter;

ExpandableChildList expandableChildList;




public ExpandableListAdapter(Context context, ArrayList<ExpandParentData> group) {
    this.context=context;
    this.group=group;

}

@Override
public int getGroupCount() {
    return group.size();
}

@Override
public int getChildrenCount(int groupPosition) {
    ArrayList<ExpandChildData> childDatas=group.get(groupPosition).getExpandChildData();
    return childDatas.size();
}

@Override
public Object getGroup(int groupPosition) {
    return  group.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {

    ArrayList<ExpandChildData> chList = group.get(groupPosition).getExpandChildData();
    return chList.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 true;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

     ImageView mIVExpandCollapse;

    ExpandParentData group = (ExpandParentData) getGroup(groupPosition);


    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.expand_header_row,parent,false);
        mTVHeader = (TextView) convertView.findViewById(R.id.txt_header_name);
        mTVHeaderValue= (TextView) convertView.findViewById(R.id.txt_header_value);
    }

    mTVHeader.setText(group.getHeaderOne());
    mTVHeaderValue.setText(group.getHeaderTwo());
    mIVExpandCollapse = (ImageView) convertView.findViewById(R.id.iv_expand_collapse);

    if (isExpanded) {
        mIVExpandCollapse.setImageResource(R.drawable.arrowexpand);
    } else {
        mIVExpandCollapse.setImageResource(R.drawable.arrowcollapse);
    }

    return convertView;

}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {


    ArrayList<ExpandChildData> childDatas=group.get(groupPosition).getExpandChildData();


    if (convertView==null) {

        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.expand_child_parent, parent, false);
        expand_child_parent = (ExpandableListView) convertView.findViewById(R.id.expand_child_parent);

        expandableChildAdapter=new ExpandableChildAdapter(context, childDatas);
        if (expand_child_parent!=null) {
            expand_child_parent.setAdapter(expandableChildAdapter);
            expand_child_parent.setGroupIndicator(null);
        }

    }

    return convertView;

}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

}

  

儿童适配器代码。

public class ExpandableChildAdapter extends BaseExpandableListAdapter {

private static final String TAG = ExpandableChildAdapter.class.getSimpleName();
Context context;
ArrayList<ExpandChildData> expandChildData;

private TextView mTVHeader, mTVHeaderValue, mTVChild, mTVChildValue;


public ExpandableChildAdapter(Context context, ArrayList<ExpandChildData> expandChildData) {
    this.context = context;
    this.expandChildData = expandChildData;


}

@Override
public int getGroupCount() {
    return expandChildData.size();
}

@Override
public int getChildrenCount(int i) {
    ArrayList<ChildData> childDatas = expandChildData.get(i).getChildData();
    return childDatas.size();
}

@Override
public Object getGroup(int i) {


    return expandChildData.get(i);
}

@Override
public Object getChild(int i, int i1) {

    ArrayList<ChildData> chList = expandChildData.get(i).getChildData();

    Log.e(TAG, "YES CALLED " + chList.get(i1));

    return chList.get(i1);

}

@Override
public long getGroupId(int i) {
    Log.e(TAG, "Get Group ID " + i);
    return i;
}

@Override
public long getChildId(int i, int i1) {
    Log.e(TAG, "Get Child Id  " + i1);
    return i1;
}

@Override
public boolean hasStableIds() {
    return true;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

    TextView mIVExpandCollapse;

    ExpandChildData group = (ExpandChildData) getGroup(groupPosition);


    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.expand_child_row, parent, false);
        mTVHeader = (TextView) convertView.findViewById(R.id.txt_child_header_name);
        mTVHeaderValue = (TextView) convertView.findViewById(R.id.txt_child_header_value);
    }

    mTVHeader.setText(group.getChildHeaderOne());
    mTVHeaderValue.setText(group.getChildHeaderTwo());


    mIVExpandCollapse = (TextView) convertView.findViewById(R.id.iv_expand_plus);

    if (isExpanded) {
        mIVExpandCollapse.setText("-");
    } else {
        mIVExpandCollapse.setText("+");
    }

    return convertView;

}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {


    ChildData child = (ChildData) getChild(groupPosition, childPosition);


    Log.e(TAG, "YES CALLED " + child);

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.child_data, parent, false);
        mTVChild = (TextView) convertView.findViewById(R.id.txt_child_name);
        mTVChildValue = (TextView) convertView.findViewById(R.id.txt_child_value);
    }

    convertView.setMinimumHeight(parent.getHeight());


    mTVChild.setText(child.getChildDataOne());
    mTVChildValue.setText(child.getChildDataTwo());


    Log.e(TAG, "Child View " + convertView);

    Log.e(TAG, "Child Data One  in View " + child.getChildDataOne());

    Log.e(TAG, "Child Data Two in View " + child.getChildDataTwo());

    return convertView;


}

@Override
public boolean isChildSelectable(int i, int i1) {
    return true;
}

}

0 个答案:

没有答案