我试图将我的数据添加到列表视图。我正在使用适配器。列表视图内部有单选按钮和一些字段。
class StocktakeEditViewAdaptor : BaseAdapter<Model.FileRecord>
{
private Dictionary<int, bool> checkDictionary = new Dictionary<int, bool>();
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = items[position];
View view = convertView;
//if (view == null)
{
view = context.LayoutInflater.Inflate(Resource.Layout.StockTakeEditDetailList, null);
view.DuplicateParentStateEnabled = true;
createdview.Add(view);
RadioButton lblradio = view.FindViewById<RadioButton>(Resource.Id.lblradio);
lblradio.Tag = item.FileRecord_ID + ":" + item.ST_filename + ":" + item.ST_BinLoc;
lblradio.Checked = checkDictionary[position]; //add position here
lblradio.SetOnCheckedChangeListener(null);
lblradio.SetOnCheckedChangeListener(new CheckedChangeListener(this.context));
view.FindViewById<TextView>(Resource.Id.txtLineNo).Text = item.FileRecord_ID.ToString(); //my field in adapter.
view.FindViewById<TextView>(Resource.Id.txtbinloc).Text = item.ST_BinLoc.ToString();
view.FindViewById<TextView>(Resource.Id.txtBarcodett).Text = item.ST_Barcode.ToString();
view.FindViewById<TextView>(Resource.Id.txtQtytt).Text = item.ST_Qty.ToString();
if (!view.HasOnClickListeners)
view.Click += View_LongClick;
view.RefreshDrawableState();
}
return view;
}
public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
{
for (int i = 0; i < checkDictionary.Count(); i++)
{
if (i == (int)buttonView.Tag)
{
checkDictionary[i] = true; //error on here
}
else
{
checkDictionary[i] = false; //error on here
}
}
}
我可以在列表视图中显示我的记录。但是单选按钮可以选择多个。我不想选择多条记录。
当年话下
波斯汪
相关分类