gpt4 book ai didi

c# - 如何实现多选?检查 "All file"以从适配器中选择所有文件

转载 作者:太空宇宙 更新时间:2023-11-03 12:07:17 24 4
gpt4 key购买 nike

在复选框中选中“选择所有文件”,以选中适配器中的所有复选框。

public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = items[position];
View view = convertView;

view = context.LayoutInflater.Inflate(Resource.Layout.StockTakeUploadAdapter, null);
view.DuplicateParentStateEnabled = true;
createdview.Add(view);

CheckBox chkBoxFileName = view.FindViewById<CheckBox>(Resource.Id.chkBoxFileName);
chkBoxFileName.Tag = position;
chkBoxFileName.SetOnCheckedChangeListener(this);

view.FindViewById<TextView>(Resource.Id.lblFileName).Text = item.ST_filename.ToString();
view.FindViewById<TextView>(Resource.Id.lblFileStatus).Text = item.ST_UploadStatus.ToString();


if (!view.HasOnClickListeners)
view.Click += View_LongClick;
view.RefreshDrawableState();
return view;
}

当点击复选框“全选”时,适配器可以选择适配器中的所有记录。 enter image description here

最佳答案

你可以这样做,在你的 Activity 中:

   CheckBox selectAll = FindViewById<CheckBox>(Resource.Id.button1);
selectAll.SetOnCheckedChangeListener(this);


public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
{
adapter.SelectAll(isChecked);
}

在你的适配器中,使用一个集合来保存状态:

  private Dictionary<int, bool> checkBoxStatus = new Dictionary<int, bool>();

public MyAdapter(int[] value)//in your constructor, it will be instantiated
{
item = value;
for (int i = 0; i < item.Length; i++)
{
checkBoxStatus.Add(i,false);
}
}

public void SelectAll(bool isChecked)
{
for (int i = 0; i < item.Length; i++)
{
checkBoxStatus[i]= isChecked;
}
NotifyDataSetChanged();
}
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = items[position];
View view = convertView;

view = context.LayoutInflater.Inflate(Resource.Layout.StockTakeUploadAdapter, null);
view.DuplicateParentStateEnabled = true;
createdview.Add(view);

CheckBox chkBoxFileName = view.FindViewById<CheckBox>(Resource.Id.chkBoxFileName);
chkBoxFileName .Checked = checkBoxStatus[position];
chkBoxFileName.Tag = position;
chkBoxFileName.SetOnCheckedChangeListener(this);

view.FindViewById<TextView>(Resource.Id.lblFileName).Text = item.ST_filename.ToString();
view.FindViewById<TextView>(Resource.Id.lblFileStatus).Text = item.ST_UploadStatus.ToString();


if (!view.HasOnClickListeners)
view.Click += View_LongClick;
view.RefreshDrawableState();
return view;
}

public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
{
checkBoxStatus[(int) buttonView.Tag]= isChecked;
NotifyDataSetChanged();

}

关于c# - 如何实现多选?检查 "All file"以从适配器中选择所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54302018/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com