问题
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