title: Remember selected day and show list after refresh
body: <p>I’ve a layout (Let’s call it WeekReservations) with different textview which represent the days of this month. For each day there’s a listview with reservations. The listview is for each day different. Also for each selected day you can make a reservation.</p>
  
  <p><strong>First time landing on WeekReservations</strong></p>
  
  <p><a href="https://i.stack.imgur.com/MJRhB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MJRhB.png" alt="enter image description here"></a>
  First time landing on this page won't show anything until you choose a day.</p>
  
  <p><strong>After selecting a day</strong></p>
  
  <p><a href="https://i.stack.imgur.com/fzv8l.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fzv8l.png" alt="enter image description here"></a></p>
  
  <p>Default, if I land on this page there are no selected days. Which means I can’t see a listview until I choose a day. When I make a reservation and submit it, I will be directed back to the WeekReservations page (to redirect them back, I’ve refreshed this page). </p>
  
  <p>To do the refresh I used these line of codes:</p>
  
  <pre><code>var intent = new Intent (this, typeof(WeekViewActivity));
              intent.SetFlags (ActivityFlags.ClearTop);
              StartActivity (intent);
  </code></pre>
  
  <p>All the data will be updated correctly. Until here it works all fine.</p>
  
  <p>But the problem is, when I’m directed back to the WeekReservations page, I won’t be seeing the day with the list of reservations where I made my reservation. I need to choose the day again (the day where I made the reservation) to see my recent made reservation. </p>
  
  <p>I've tried to remember the id selected day and pass it through the activities and pass it back to the WeekReservations activity. But this gave me an error. because if it's the first time landing on this page there won't be anything to pass to this WeekReservations activity.</p>
  
  <p><strong>My question is:</strong> </p>
  
  <p>Is there a way to remember which day the user has selected (to make a reservation) and show this selected day with list of reservations after the refresh?</p>
  
  <p>If it's still unclear what I'm asking or lacking details, please feel free to point that out. I'll do my best to explain myself</p>
  
  <hr>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Below is my code how I did it until now:</p>
  
  <p><strong>WeekViewActivity.cs</strong></p>
  
  <p>Code for choosing a day and show the listview and making a reservation</p>
  
  <pre><code>namespace iChargeClassTest
  {
      [Activity (Label = "WeekViewActivity", Theme =     "@android:style/Theme.NoTitleBar")]          
      public class WeekViewActivity : Activity
  {
      List&lt;WeekReservationClass&gt; result;
      string myCPID;
      string myCPAddress;
  
      TextView showDay1, showDay2, showDay3, showDay4, showDay5, showDay6, showDay7, selectedDay;
      Button makeBooking;
  
      int totalDays;
      DateTime chosenDateCP;
      List&lt;WeekReservationClass&gt; newList = new List&lt;WeekReservationClass&gt; ();
  
      private List&lt;ReservationTime&gt; myItems;
      private ListView mListView;
  
      protected async override void OnCreate (Bundle savedInstanceState)
      {
          base.OnCreate (savedInstanceState);
          SetContentView (Resource.Layout.WeekViewLayout);
  
          TextView showCurrentMonth = FindViewById&lt;TextView&gt; (Resource.Id.txtCurrentMonth);
          showCurrentMonth.Text = DateTime.Now.ToMonthName ();
  
          showDay1 = FindViewById&lt;TextView&gt; (Resource.Id.txtToday);
          showDay2 = FindViewById&lt;TextView&gt; (Resource.Id.txtDay2);
          showDay3 = FindViewById&lt;TextView&gt; (Resource.Id.txtDay3);
          showDay4 = FindViewById&lt;TextView&gt; (Resource.Id.txtDay4);
          showDay5 = FindViewById&lt;TextView&gt; (Resource.Id.txtDay5);
          showDay6 = FindViewById&lt;TextView&gt; (Resource.Id.txtDay6);
          showDay7 = FindViewById&lt;TextView&gt; (Resource.Id.txtDay7);
  
          makeBooking = FindViewById&lt;Button&gt; (Resource.Id.btnBooking);
  
          selectedDay = FindViewById&lt;TextView&gt; (Resource.Id.txtSelectedDay);
  
          showDay1.Text = DateTime.Today.Day.ToString ();
          showDay2.Text = DateTime.Today.AddDays (1).Day.ToString ();
          showDay3.Text = DateTime.Today.AddDays (2).Day.ToString ();
          showDay4.Text = DateTime.Today.AddDays (3).Day.ToString ();
          showDay5.Text = DateTime.Today.AddDays (4).Day.ToString ();
          showDay6.Text = DateTime.Today.AddDays (5).Day.ToString ();
          showDay7.Text = DateTime.Today.AddDays (6).Day.ToString ();
  
          mListView = FindViewById&lt;ListView&gt; (Resource.Id.myListView);
          myItems = new List&lt;ReservationTime&gt; ();
  
          myCPID = Settings.CharchingPoint_ID;
          myCPAddress = Settings.CharchingPointAddress;
          selectedDay.Text = myCPAddress;
  
          //get all the reservations from webservice
          try {
              string pathUrl = "reservations/weekReservations/";
              string currentToken = Settings.Token;
  
              var getResponse = await RequestClass.GetData (pathUrl, currentToken);
  
              result = JsonConvert.DeserializeObject&lt;List&lt;WeekReservationClass&gt;&gt; (getResponse);
  
          } catch (Exception ex) {
              Console.WriteLine ("Check error: " + ex);
          }
  
          showDay1.Click += ShowDay1_Click;
          showDay2.Click += ShowDay2_Click;
          showDay3.Click += ShowDay3_Click;
          showDay4.Click += ShowDay4_Click;
          showDay5.Click += ShowDay5_Click;
          showDay6.Click += ShowDay6_Click;
          showDay7.Click += ShowDay7_Click;
  
          makeBooking.Click += MakeBooking_Click;
      }
  
      void MakeBooking_Click (object sender, EventArgs e)
      {
          Settings.ChosenReservationDate = chosenDateCP.ToString ();
          Settings.CharchingPoint_ID = myCPID;
          StartActivity (typeof(ReservationHoursActivity));
      }
  
      //get and show reservation in listview
      void ShowDay7_Click (object sender, EventArgs e)
      {
          totalDays = int.Parse (showDay7.Text) - DateTime.Today.Day;
          chosenDateCP = DateTime.Today.AddDays (totalDays);
  
          myItems.Clear ();
          newList.Clear ();
          mListView.Adapter = null;
  
          //loop through json to get only reservation for day 7
          for (int i = 0; i &lt; result.Count; i++) {
              Console.WriteLine (Convert.ToDateTime (result [i].startTime));
  
              if (Convert.ToDateTime (result [i].startTime).Date == chosenDateCP.Date &amp;&amp; result [i].chargingPointID == myCPID) {
  
                  var newReservation = new WeekReservationClass ();
  
                  newReservation._id = result [i]._id;
                  newReservation.endTime = result [i].endTime;
                  newReservation.startTime = result [i].startTime;
                  newReservation.chargingPointID = result [i].chargingPointID;
                  newReservation.userID = result [i].userID;
                  newReservation.__v = result [i].__v;
                  newReservation.modified_at = result [i].modified_at;
                  newReservation.created_at = result [i].created_at;
  
                  newList.Add (newReservation);
              } else {
                  Console.WriteLine ("failed");
              }
          }
  
          //loop through filtered list and show in listview
          for (int j = 0; j &lt; newList.Count; j++) {
              Console.WriteLine (newList [j].startTime);
              myItems.Add (new ReservationTime () {
                  StartTime = Convert.ToDateTime (newList [j].startTime), EndTime = Convert.ToDateTime (newList [j].endTime)
              });
          }
          MyListViewAdapter myadapter = new MyListViewAdapter (this, myItems);
  
          if (myadapter.IsEmpty) {
              Toast.MakeText (this, "There are no reservations for today", ToastLength.Long).Show ();
          } else {
              mListView.Adapter = myadapter;
          }
  
      }
  
      void ShowDay6_Click (object sender, EventArgs e)
      {
          totalDays = int.Parse (showDay6.Text) - DateTime.Today.Day;
          chosenDateCP = DateTime.Today.AddDays (totalDays);
  
          myItems.Clear ();
          newList.Clear ();
          mListView.Adapter = null;
  
          for (int i = 0; i &lt; result.Count; i++) {
              Console.WriteLine (Convert.ToDateTime (result [i].startTime));
              if (Convert.ToDateTime (result [i].startTime).Date == chosenDateCP.Date &amp;&amp; result [i].chargingPointID == myCPID) {
  
                  var newReservation = new WeekReservationClass ();
  
                  newReservation._id = result [i]._id;
                  newReservation.endTime = result [i].endTime;
                  newReservation.startTime = result [i].startTime;
                  newReservation.chargingPointID = result [i].chargingPointID;
                  newReservation.userID = result [i].userID;
                  newReservation.__v = result [i].__v;
                  newReservation.modified_at = result [i].modified_at;
                  newReservation.created_at = result [i].created_at;
  
                  newList.Add (newReservation);
              } else {
                  Console.WriteLine ("failed");
              }
          }
          for (int j = 0; j &lt; newList.Count; j++) {
              Console.WriteLine (newList [j].startTime);
              myItems.Add (new ReservationTime () {
                  StartTime = Convert.ToDateTime (newList [j].startTime), EndTime = Convert.ToDateTime (newList [j].endTime)
              });
          }
          MyListViewAdapter myadapter = new MyListViewAdapter (this, myItems);
  
          if (myadapter.IsEmpty) {
              Toast.MakeText (this, "There are no reservations for today", ToastLength.Long).Show ();
          } else {
              mListView.Adapter = myadapter;
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>ReservationHoursActivity.cs</strong></p>
  
  <p>Code for making a reservation and submit it to the webwervice</p>
  
  <pre><code>namespace iChargeClassTest
  {
  [Activity (Label = "ReservationHoursActivity", Theme = "@android:style/Theme.NoTitleBar")]          
  public class ReservationHoursActivity : Activity, TimePickerDialog.IOnTimeSetListener
  {
      string myDate;
      string myCP_ID;
      string selectedButtonDate;
  
      Button submitButtonMyslot;
  
      protected override void OnCreate (Bundle savedInstanceState)
      {
          base.OnCreate (savedInstanceState);
          SetContentView (Resource.Layout.ReservationHoursLayout);
  
          myDate = Settings.ChosenReservationDate;
          myCP_ID = Settings.CharchingPoint_ID;
  
          submitButtonMyslot = FindViewById&lt;Button&gt; (Resource.Id.btnSubmitSlot);
          submitButtonMyslot.Click += SubmitButtonMyslot_Click;
  
          /*
          Code for time picker
          */
      }
  
      /*
          methodes for time picker
      */
  
      //submit reservation
      async void SubmitButtonMyslot_Click (object sender, EventArgs e)
      {
          //post submitted data to webservice
          try {
              string stringDateTimeEND = Convert.ToDateTime (myDate).ToShortDateString () + " " + Convert.ToDateTime (time_display_End.Text).ToLongTimeString ();
              string stringDateTimeSTART = Convert.ToDateTime (myDate).ToShortDateString () + " " + Convert.ToDateTime (time_display_Start.Text).ToLongTimeString ();
  
              DateTime dtEnd = Convert.ToDateTime (stringDateTimeEND);
              DateTime dtStart = Convert.ToDateTime (stringDateTimeSTART);
  
              string utcEnd = dtEnd.ToUniversalTime ().ToString ("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
              string utcStart = dtStart.ToUniversalTime ().ToString ("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");
  
              var postData = "endTime=" + utcEnd;
              postData += "&amp;startTime=" + utcStart;
              postData += "&amp;chargingPointID=" + myCP_ID;
              postData += "&amp;userID=" + Settings.User_ID;
  
              string pathUrl = "reservations/add";
  
              var post_response = await RequestClass.PostData (postData, pathUrl, Settings.Token);
  
              Toast.MakeText (this, "Your Booking is succefully send!", ToastLength.Long).Show ();
  
              //restart weekactivity to refresh
              var intent = new Intent (this, typeof(WeekViewActivity));
              intent.SetFlags (ActivityFlags.ClearTop);
              StartActivity (intent);
  
              Finish ();//close the reservationHoursActivity
  
          } catch (WebException exception) {
              string responseText;
              using (var reader = new StreamReader (exception.Response.GetResponseStream ())) {
                  responseText = reader.ReadToEnd ();
                  Console.WriteLine (responseText);
              }
              Toast.MakeText (this, "Reservation Failed!", ToastLength.Long).Show ();
          }
      }
  }
  </code></pre>
  
  <p>}</p>