当项目点击xamarin andriod时,如何检查ListView的CheckBox

时间:2017-03-06 17:09:23

标签: java c# android listview xamarin.android

我有列表视图,当我点击OnListItemClick列表中的项目复选框时,我想要的复选框和textview .. 这是我的适配器类:

public class ViewHoldername : Java.Lang.Object
    {
        public EditText etdName { get; set; }
        public EditText etdTitle { get; set; }


    }
class listViewNames : BaseAdapter<logINsnc.Customers_transfer>
    {

     private ISharedPreferences savePreferences;
     static     private ISharedPreferencesEditor savePrefsEditor;
     private Boolean saveLogin;  
     public static  CheckBox namechecbox ;
     public static List<string> listNameChecked = new List<string>();
     Activity activity;

     List<logINsnc.Customers_transfer> ArriveList = new               List<logINsnc.Customers_transfer>();

   // SQliteDB bb = new SQliteDB();
    logINsnc bb = new logINsnc();

    async public Task<List<logINsnc.Customers_transfer>> Add_DataList(string s)
    {

      //  string Get =  ExpandableListAdapter.Globals.voucher;
        ArriveList = await bb.DetailsNamelistForPOpUp(s);
        return ArriveList;

    }
    public string GetVoucher()
    {
        string voucher = "";
        return voucher;
    }
    public listViewNames()
    {

    }

    public listViewNames(Activity activity,   List<logINsnc.Customers_transfer> Arrive)
        : base()
    {

        this.activity = activity;
        this.ArriveList = Arrive;
    }


    public override int Count
    {
        get
        {
            return ArriveList.Count();
        }
    }


    public override Java.Lang.Object GetItem(int position)
    {
        return position;
    }


    public override long  GetItemId(int position)
    {
        return ArriveList[position].SrvOrd_Sub_Id;
    }


    public override logINsnc.Customers_transfer this[int position]
    {
        get { return ArriveList[position]; }
    }




    public override View GetView(int position, View convertView, ViewGroup  parent)
    {
          savePreferences = Application.Context.GetSharedPreferences("savePrefs", FileCreationMode.Private);
        Globals.custimersCount = Count;

     activity.LayoutInflater.Inflate(Resource.Layout.Details_Template, null);
        var item = ArriveList[position];
        View view = convertView;

        if (view == null) // no view to re-use, create new
            view = activity.LayoutInflater.Inflate(Resource.Layout.Custmize_Name_layout, null);

        Globals.Ser_Sub = item.SrvOrd_Sub_Id;


         view.FindViewById<TextView>(Resource.Id.etdNamelis).Text = item.Name.ToString();
         view.FindViewById<TextView>(Resource.Id.etdTitle).Text = item.Title;
         namechecbox = view.FindViewById<CheckBox>(Resource.Id.checkBoxnam);
      //   checkBoxButton = (CheckBox)convertView.FindViewById(Resource.Id.checkBoxButton);
         namechecbox.Tag = item.Title + ";"+ position+";"+item.Name;


         savePrefsEditor = savePreferences.Edit();

         saveLogin = savePreferences.GetBoolean("saveLogind" + position + item.Name, false);
         if (saveLogin == true)
         { 
              namechecbox.Checked = true;

         }  

        namechecbox.SetOnCheckedChangeListener(null);

        namechecbox.SetOnCheckedChangeListener(new CheckedChangeListener(this.activity)); 

         return view;

    }


    private class CheckedChangeListener : Java.Lang.Object, CompoundButton.IOnCheckedChangeListener
    {
        private Activity activity;

        public CheckedChangeListener(Activity activity)
        {
            this.activity = activity;
        }

        public void OnCheckedChanged(CompoundButton buttonView, bool isChecked)
        {

            String[] tag = buttonView.Tag.ToString().Split(';');
            string name = tag[0];
               if (isChecked && !savePreferences.Contains("saveLogind" + tag[1] + tag[2]  ))

            {

            savePrefsEditor.PutBoolean("saveLogind" + tag[1]+tag[2], true);

            savePrefsEditor.Commit();  

                listNameChecked.Add(name);
                Globals.listName = listNameChecked;

            }
            else
            {

                listNameChecked.Remove(name);

               editor.Remove("saveLogind" + tag[1] + tag[2] );
               savePrefsEditor.Commit(); 
                Globals.listName = listNameChecked;


            }
        }
    }

这是我的活动

  public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {

            base.OnCreateView(inflater, container, savedInstanceState);

            var view = inflater.Inflate(Resource.Layout.PopUpLayont, container, false);
            SetHasOptionsMenu(true);
            TextView textView2 = view.FindViewById<TextView>(Resource.Id.textView2);
            listviewview = view.FindViewById<ListView>(Resource.Id.listViewName);

            Button Divide = view.FindViewById<Button>(Resource.Id.Divv);
            Divide.Click +=Divide_Click;
            DialogFragment s = new DialogFragment();
            Dialog.SetTitle("   Customers Details ");

        //    Dialog.Window.RequestFeature(WindowFeatures.NoTitle);
            s.Cancelable = false;

            return view;
        }
  private void Divide_Click(object sender, EventArgs e)
      {//....}
  private void OnListItemClick(object sender, AdapterView.ItemClickEventArgs e)
      {



           Toast.MakeText(this.Activity, "clickedd", ToastLength.Long).Show();
      }

0 个答案:

没有答案