我在我的项目中使用了Expandable列表。我扩展了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());
它的工作只是我扩展的第一个位置。怎么能为每个孩子设置标签?我重写onGroupExpanded,但我不知道如何使用它。
答案 0 :(得分:0)
必须从if获得以下两行。
holder.checked.setTag(groupPosition*100+childPosition);
holder.text.setTag(groupPosition*100+childPosition);