在可扩展列表中将唯一 ID 设置为子级



我在项目中使用可扩展列表。我扩展了 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());

它只适用于我扩展的第一个位置。 如何为每个孩子设置标签做一些事情? 我覆盖了组扩展,但我不知道如何使用它。

必须从if中取出两个后续行。

 holder.checked.setTag(groupPosition*100+childPosition);
 holder.text.setTag(groupPosition*100+childPosition);

最新更新