set Tag to Every Child in expandable list

只愿长相守 提交于 2020-01-25 18:23:25

问题


I using Expandable list in my project.I extends BaseExpandableListAdapter,I want to set unique tag to every child, i use following code to set tag:

     public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    ArrayList<String> childtemp= (ArrayList<String>) childitems.get(groupPosition);


    final ViewHolder holder;
    View v = convertView;

    if (v == null) {
        holder = new ViewHolder();
        v = inflatter.inflate(R.layout.childrow, null);
        holder.text = (TextView) v.findViewById(R.id.childrow);
        holder.checked = (CheckBox) v.findViewById(R.id.childcheck);
        v.setTag(holder);

        holder.checked.setChecked(false);
        holder.checked.setTag(groupPosition*100+childPosition);
        holder.text.setTag(groupPosition*100+childPosition);
     }
     else {
        ((ViewHolder) v.getTag()).text.setTag(groupPosition*100+childPosition);
        holder = (ViewHolder) v.getTag();
        getid = (Integer) holder.text.getTag();
        check(getid , holder);  
        }

     holder.text.setText(childtemp.get(childPosition).toString());

and its working for first position that i expand but when I expand another position tag not set because convertView is not null. how can doing something that for every child set tag?? i override onGroupExpanded but i dont know how use that.


回答1:


public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    List<String> childtemp= (List<String>) childitems.get(groupPosition);

    final ViewHolder holder;
    View v = convertView;

    if (v == null) {
        holder = new ViewHolder();
        v = inflatter.inflate(R.layout.childrow, null);
        holder.text = (TextView) v.findViewById(R.id.childrow);
        holder.checked = (CheckBox) v.findViewById(R.id.childcheck);
        v.setTag(holder);

        holder.checked.setChecked(false);
     }
     else {
        ((ViewHolder) v.getTag()).text.setTag(groupPosition*100+childPosition);
        holder = (ViewHolder) v.getTag();
        getid = (Integer) holder.text.getTag();
        check(getid , holder);  
     }

     holder.checked.setTag(groupPosition*100+childPosition);
     holder.text.setTag(groupPosition*100+childPosition);
     holder.text.setText(childtemp.get(childPosition).toString());


来源:https://stackoverflow.com/questions/18997898/set-tag-to-every-child-in-expandable-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!