Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Need to save checkbox state in a custom adapter listview

$
0
0

i have DialogFragment contians listview have check box and text view i want saved state of checkBox after checked i do that saved the states in ISharedPreferencesbut it not worked What is problem ??
this is my listViewNames Adapter

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 && namechecbox.Checked == false )
            {

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

            savePrefsEditor.Commit();

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

            }
            else
            {

                listNameChecked.Remove(name);
               savePrefsEditor.PutBoolean("saveLogind" + tag[1]+tag[2], true).Clear();
               savePrefsEditor.Clear();
               savePrefsEditor.Commit();
                Globals.listName = listNameChecked;


            }
        }
    }



    public static class Globals
    {
        public static int  Ser_Sub { get; set; }
        public static List<string> listName;
         public static int custimersCount { get; set; }
        // public static int TransName { get; set; }
        public static string nameChecked { get; set; }
    }



}

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>