如何为动态ExpandableListView添加多个图像?

时间:2015-07-31 03:26:13

标签: android

我的代码:

@Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        final String childText = (String) getChild(groupPosition, childPosition);

        if (convertView == null) {
            LayoutInflater infalInflater = (LayoutInflater) this.mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = infalInflater.inflate(R.layout.child_list_view,null);
        }

        ImageView imgListChild = (ImageView) convertView.findViewById(R.id.my_icon);
        if(mObjectList[childPosition].getFlagStatus()==2){
            imgListChild.setImageResource(R.drawable.icon_2);
        }if(mObjectList[childPosition].getFlagStatus()==1){
            imgListChild.setImageResource(R.drawable.icon_1);
        }if(mObjectList[childPosition].getFlagStatus()==0){
            imgListChild.setVisibility(View.VISIBLE);
        }
        return convertView;
    }

我想要的是这样的:

enter image description here

但如果我像上面那样编码,它将使所有的ImageView可见并具有相同的图像。请告诉我如何解决这个问题。谢谢;)

1 个答案:

答案 0 :(得分:0)

为什么不向特定的特定孩子添加特定图像

@Override
public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    final String childText = (String) getChild(groupPosition, childPosition);

    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this.mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.child_list_view,null);
    }

    ImageView imgListChild = (ImageView) convertView.findViewById(R.id.my_icon);
    if(childPosition==0)
    {
         imgListChild.setImageResource(R.drawable.icon2);
    }
    /*And so on*/
    return convertView;
}