public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            ViewGroup root = (ViewGroup)inflater.Inflate(Resource.Layout.fragment_content_plotaddedit, null);

            farmid       = Arguments.GetString("siteparam");
            plotid       = Arguments.GetString("siteparam0");
            soilMstrBasu = this.GetSoilMasterDtl(farmid);

            btn_add_new_plot        = root.FindViewById <Button>(Resource.Id.btn_add_new_plot);
            btn_cancel_plot         = root.FindViewById <Button>(Resource.Id.btn_cancel_plot);
            btn_add_new_plot.Click += (sndr, argus) => AddPlot_Clicked(sndr, argus, this.Activity);
            btn_cancel_plot.Click  += (sndr, argus) => Cancel_Selection(sndr, argus, this.Activity);

            input_plot_name  = root.FindViewById <EditText>(Resource.Id.input_plot_name);
            input_plot_size  = root.FindViewById <EditText>(Resource.Id.input_plot_size);
            input_plot_notes = root.FindViewById <EditText>(Resource.Id.input_plot_notes);

            spinner_soilph                 = root.FindViewById <Spinner>(Resource.Id.spinner_soilph);
            spinner_soiltype               = root.FindViewById <Spinner>(Resource.Id.spinner_soiltype);
            spinner_soilph.ItemSelected   += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_soilph_ItemSelected);
            spinner_soiltype.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_soiltype_ItemSelected);
            List <string> lstPh = new List <string>();

            lstPh.Add("Unknown");
            lstPh.AddRange(soilMstrBasu.soilphdetail.Select(p => p.SoilPhvalue.ToString()).ToList());
            spinner_soilph.Adapter = new ArrayAdapter <string>(this.Activity, Android.Resource.Layout.SimpleSpinnerItem, lstPh);
            List <string> lsttype = new List <string>();

            lsttype.Add("Unknown");
            lsttype.AddRange(soilMstrBasu.soildetail.Select(s => s.SoilName).ToList());
            spinner_soiltype.Adapter = new ArrayAdapter <string>(this.Activity, Android.Resource.Layout.SimpleSpinnerItem, lsttype);

            isorganic_switch = root.FindViewById <Switch>(Resource.Id.isorganic_switch);
            isorganic_switch.CheckedChange += delegate(object sender, CompoundButton.CheckedChangeEventArgs e)
            {
                isorganic = e.IsChecked;

                /*var toast = Toast.MakeText(this.Activity, (e.IsChecked ? "Admin mode activated. Login with administrative credential" : "Admin mode de-activated. Login with non-admin user credential"),
                 *  ToastLength.Long);
                 * toast.Show();*/
            };

            if (!string.IsNullOrEmpty(plotid))
            {
                ProgressDialog progressDialog = ProgressDialog.Show(this.Activity, "Please wait...", "Fetching plot details...", true);
                new Thread(new ThreadStart(delegate
                {
                    this.Activity.RunOnUiThread(() => this.GetPlotById(progressDialog, this.Activity, plotid, soilMstrBasu));
                })).Start();
            }

            return(root);
        }
        private void GetPlotById(ProgressDialog dialog, Activity curActivity, string plotid, SoilDataResponse sm)
        {
            try
            {
                string mStringLoginInfo    = string.Empty;
                string mStringSessionToken = string.Empty;
                try
                {
                    objdb = new DBaseOperations();
                    var lstu = objdb.selectTable();
                    if (lstu != null && lstu.Count > default(int))
                    {
                        var uobj = lstu.FirstOrDefault();
                        if (uobj.Password == " ")
                        {
                            throw new Exception("Please login again");
                        }
                        mStringLoginInfo    = uobj.EmailId;
                        mStringSessionToken = uobj.AuthToken;
                    }
                }
                catch { }

                var client  = new RestClient(Common.UrlBase);
                var request = new RestRequest("Plot/GetPlotDetailsById", Method.GET);
                request.AddHeader("Content-Type", "application/json");
                request.AddHeader("TokenKey", mStringSessionToken);
                request.AddQueryParameter("PlotId", System.Net.WebUtility.UrlEncode(plotid));
                IRestResponse response = client.Execute(request);
                var           content  = response.Content;

                var responseObj = Newtonsoft.Json.JsonConvert.DeserializeObject <List <PlotDetailResponse> >(content);
                if (responseObj != null && responseObj.Count() > default(int))
                {
                    var obj = responseObj.FirstOrDefault();
                    obj.PlotId               = plotid;
                    input_plot_name.Text     = obj.PlotName;
                    input_plot_size.Text     = obj.PlotSize.ToString();
                    input_plot_notes.Text    = obj.Notes;
                    isorganic_switch.Checked = obj.Organic;

                    ArrayAdapter adap = (ArrayAdapter)spinner_soilph.Adapter;
                    int          a    = default(int);
                    if (sm.soilphdetail.Where(p => p.SoilPhId == obj.SoilPhId).FirstOrDefault() != null)
                    {
                        a = adap.GetPosition(sm.soilphdetail.Where(p => p.SoilPhId == obj.SoilPhId).Select(s => s.SoilPhvalue).FirstOrDefault().ToString());
                    }
                    spinner_soilph.SetSelection(a);

                    ArrayAdapter adap_ = (ArrayAdapter)spinner_soiltype.Adapter;
                    int          a_    = default(int);
                    if (sm.soildetail.Where(p => p.SoilId == obj.SoilId).FirstOrDefault() != null)
                    {
                        a_ = adap_.GetPosition(sm.soildetail.Where(p => p.SoilId == obj.SoilId).Select(s => s.SoilName).FirstOrDefault().ToString());
                    }
                    spinner_soiltype.SetSelection(a_);

                    btn_add_new_plot.Text = "Update";
                }
            }
            catch (Exception ex)
            {
                curActivity.RunOnUiThread(() =>
                {
                    Android.App.AlertDialog.Builder alertDiag = new Android.App.AlertDialog.Builder(curActivity);
                    alertDiag.SetTitle(Resource.String.DialogHeaderError);
                    alertDiag.SetMessage(ex.Message);
                    alertDiag.SetIcon(Resource.Drawable.alert);
                    alertDiag.SetPositiveButton(Resource.String.DialogButtonOk, (senderAlert, args) =>
                    {
                        MyFarmDashboardFragment objFragment           = new MyFarmDashboardFragment();
                        Android.Support.V4.App.FragmentTransaction tx = FragmentManager.BeginTransaction();
                        tx.Replace(Resource.Id.m_main, objFragment, Constants.myfarmdash);
                        tx.Commit();
                    });
                    Dialog diag = alertDiag.Create();
                    diag.Show();
                    diag.SetCanceledOnTouchOutside(false);
                });
            }
            finally
            {
                if (dialog != null && dialog.IsShowing)
                {
                    dialog.Hide();
                    dialog.Dismiss();
                }
            }
        }