我的持有人班级;
class ViewHolder : Java.Lang.Object
{
public TextView kod { get; set; }
public TextView unvan { get; set; }
public TextView sebep { get; set; }
public TextView tarih { get; set; }
public TextView saat { get; set; }
public CheckBox checkBox { get; set; }
}
和我的Custom Adapter类构造函数;
public CustomAdapterZiyaretRapor(Activity context, List<Dictionary<string, string>> list)
: base()
{
this.myactivity = context;
this.ziyaretList = list;
for (int i = 0; i < ziyaretList.Count; i++)
{
itemChecked.Add(i, false);
}
}
和GetView方法;
public override View GetView(int position, View convertView, ViewGroup parent)
{
View view = convertView;
Dictionary<string, string> item = this[position];
ViewHolder holder = null;
if (view == null)
{
holder = new ViewHolder();
view = myactivity.LayoutInflater.Inflate(Resource.Layout.custom_ziyaret_raporu_listview, parent, false);
holder.kod = view.FindViewById<TextView>(Resource.Id.txt_ziy_cari_kod);
holder.unvan = view.FindViewById<TextView>(Resource.Id.txt_ziy_cari_unvan);
holder.sebep = view.FindViewById<TextView>(Resource.Id.txt_ziy_sebep);
holder.tarih = view.FindViewById<TextView>(Resource.Id.txt_ziy_tarih);
holder.saat = view.FindViewById<TextView>(Resource.Id.txt_ziy_saat);
holder.checkBox = view.FindViewById<CheckBox>(Resource.Id.chc_deneme);
holder.checkBox.SetTag(Resource.Id.chc_deneme, position);
view.Tag = holder;
holder.checkBox.CheckedChange += (object sender, CompoundButton.CheckedChangeEventArgs e) =>
{
var pos= (int) ( ((CheckBox)sender).GetTag(Resource.Id.chc_deneme));
if(e.IsChecked)
{
itemChecked[pos] = e.IsChecked;
}
};
holder.checkBox.Checked = itemChecked[position];
}
else
{
holder = view.Tag as ViewHolder;
holder.checkBox.Checked = itemChecked[position];
}
holder.kod.Text = item["mz_carikod"];
holder.unvan.Text = item["mz_carikod"];
holder.sebep.Text = item["mz_sebep"];
holder.tarih.Text = item["mz_tarih"].Split(' ')[0];
holder.saat.Text = item["mz_tarih"].Split(' ')[1];
return view;
}
我的问题是;我有自定义ListView。我想在Listview中的每一行添加复选框。没问题。但是,当我选中listview行中的复选框时,还会检查其他一些复选框。