0

我在我的项目中使用可扩展列表。我扩展了 BaseExpandableListAdapter,我想为每个孩子设置唯一标签,我使用以下代码设置标签:

     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());

它适用于我展开的第一个位置,但是当我展开另一个未设置的位置标记时,因为 convertView 不为空。如何为每个孩子设置标签做一些事情?我覆盖 onGroupExpanded 但我不知道如何使用它。

4

1 回答 1

0
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());
于 2013-09-25T07:34:58.317 回答