check "select all file" in the check box, to select all check box in adapter.

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;
    }

when click check box "select all" the adapter able to select all record in adapter. enter image description here

Answer

you could do like this, in your Activity :

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


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

in your adapter ,use a collection to save the status:

  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();

        }
  • 1
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions