Состояние флажка ListView Viewholder
У меня некоторые проблемы с моим пользовательским адаптером ListView (и его недавно реализованным viewHolder). У меня есть ListView с флажком для каждого элемента (здесь ничего нового). Проблема в том, что если в моем списке более 9 элементов, то при установке первого флажка десятый будет автоматически отмечен (то же самое для второго с одиннадцатым), как если бы был один прослушиватель для обоих элементов (и я поверьв каком-то случае).
Я прочитал о проблеме положения с listView, повторном использовании представления и способе решения ViewHolder здесь:Как я могу заставить мой ArrayAdapter следовать шаблону ViewHolder?
Но я, вероятно, сделал что-то не так, потому что этоне работает ...
public class PresenceListAdapter extends SimpleAdapter {
private LayoutInflater inflater;
private List ids;
private List statuts;
public PresenceListAdapter (Context context, List data, int resource, String[] from, int[] to, List ids, List statuts)
{
super (context, data, resource, from, to);
inflater = LayoutInflater.from (context);
this.ids = ids;
this.statuts= statuts;
}
@Override
public Object getItem (int position)
{
return super.getItem (position);
}
@Override
public View getView (int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if (convertView == null)
{
convertView = inflater.inflate (R.layout.list_text_checkbox, null);
holder = new ViewHolder();
holder.btn = (Button) convertView.findViewById(R.id.btnRetard);
holder.check = (CheckBox) convertView.findViewById(R.id.checkPresent);
if (statuts.get(position).equals("P")) {
Drawable img = inflater.getContext().getResources().getDrawable(android.R.drawable.presence_online);
holder.btn.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );
holder.btn.setEnabled(true);
holder.check.setChecked(true);
}
else if(statuts.get(position).equals("R"))
{
Drawable img = inflater.getContext().getResources().getDrawable(android.R.drawable.presence_away);
holder.btn.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );
holder.btn.setEnabled(true);
holder.check.setChecked(true);
}
else
{
Drawable img = inflater.getContext().getResources().getDrawable(android.R.drawable.presence_invisible);
holder.btn.setCompoundDrawablesWithIntrinsicBounds( img, null, null, null );
holder.check.setChecked(false);
}
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
int id = ids.get(position);
if(id != 0)
{
holder.check.setTag(id);
holder.btn.setTag(id);
}
return super.getView (position, convertView, parent);
}
static class ViewHolder {
Button btn;
CheckBox check;
}
И мой слушатель: public void changerPresent (View v) {
CheckBox checkPresent = (CheckBox) v;
int idPersonne = (Integer) checkPresent.getTag();
View parent = (View)v.getParent();
Button btn = (Button) parent.findViewById(R.id.btnRetard);
if(checkPresent.isChecked()) {
gestion.updatePresence(idPersonne, idSeance, "P");
btn.setEnabled(true);
setBtnRetardPresent(btn);
}
else
{
gestion.updatePresence(idPersonne, idSeance, "A");
btn.setEnabled(false);
setBtnRetardAbsent(btn);
}
}
Буду признателен за любую помощь,Я работаю над этим часами.
Большое спасибо.