У меня есть расширяемый список с дочерними флажками. Флажок определен в XML-файле child_helper с идентификатором «check1». По какой-то причине кажется, что несколько флажков связаны друг с другом, а не являются независимыми. Например, если в первой группе я выбираю первый элемент, он выбирает каждый третий элемент в этой группе, а во всех остальных группах он выбирает второй элемент, пропускает два и выбирает следующий элемент.
Если я выберу первые три элемента в группе 1, тогда будут выбраны все элементы во всех группах. Каким-то образом я создал 3 группы флажков вместо отдельного флажка для каждого ребенка. Я просмотрел множество руководств, в которых предлагается решить проблему с помощью специального адаптера. Я использую специальный адаптер, но не знаю, как использовать все его функции.
Возможно, лучший и гораздо более короткий вопрос заключается в том, как я должен отличать каждый дочерний флажок?
Спасибо
Это код для моего слушателя:
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Log.d( "Enter_Foods", "onChildClick: "+childPosition );
CheckBox cb = (CheckBox)v.findViewById( R.id.check1 );
if( cb != null )
cb.toggle();
return false;
}
});
}
Я думаю, что проблема заключается в одном из переопределенных методов в моем адаптере.
ExpandableListAdapter foodCategoryExpand = new ExpandableListAdapter() {
@Override
Allitemsenabled()
other override methods...
public Object getChild(int groupPosition, int childPosition) {
switch (groupPosition) {
case 0:
return group1.get(childPosition);
case 1:
return group2.get(childPosition);
case 2:
return group3.get(childPosition);
default:
return null;
}
}
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
ChildHolder holder;
if (convertView == null) {
holder = new ChildHolder();
LayoutInflater inflator = LayoutInflater.from(Enter_Foods.this);
convertView = inflator.inflate(R.layout.enter_foods_child_helper,null);
holder.tvChild = (TextView) convertView.findViewById(R.id.enter_foods_exp_lay_child);
convertView.setTag(holder);
} else {
holder = (ChildHolder) convertView.getTag();
}
//switch based on which group (main heading) child is in
switch (groupPosition) {
case 0:
holder.tvChild.setText(group1.get(childPosition));
break;
case 1:
holder.tvChild.setText(group2.get(childPosition));
break;
case 2:
holder.tvChild.setText(group3.get(childPosition));
break;
}
return convertView;
}
//create Group (main heading) view
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
GroupHolder holder;
if (convertView == null) {
holder = new GroupHolder();
LayoutInflater inflator = LayoutInflater.from(Enter_Foods.this);
//inflate xml file and then get view from that file
convertView = inflator.inflate(R.layout.enter_foods_group_helper,null);
holder.tvGroup = (TextView) convertView.findViewById(R.id.enter_foods_exp_lay_group);
convertView.setTag(holder);
} else {
holder = (GroupHolder) convertView.getTag();
}
//this actually gets the text we set in onCreate and sets it to the textView (holder)
holder.tvGroup.setText(groupTitle.get(groupPosition));
return convertView;
}
other override methods