title: Listview selecteditem in xamarin
body: <p>I have a listview that is populated with a list of terms from ItemsSource. The .Name property is the text shown on the listview. I am trying to save the .Id int property to a variable so that I can access it from another form. Essentially I want it so that when a user clicks on an item on the list it will open a form and populate it with the instance of the list associated with the item tapped.</p>
  
  <p>If the listview is populated with Book1, Book2, Book3, and Book4 with Ids of 1, 2, 3, and 4 then if the user taps Book2 I want the SelectedBook variable to be set to the .Id property of 2. Then when another form will be opened and this form will pull the appropriate book instance from the sqlite database and populate the fields with that book's information.</p>
  
  <p>I have been trying to do so with the ItemSelected property of the ListView but have been getting this error "System.NullReferenceException: Object reference not set to an instance of an object.".</p>
  
  <p>Here is the code that I used:</p>
  
  <pre><code>        public void OnSelectedItem(object sender, EventArgs args)
      {
          Book myBook = sender as Term;
          App.BookRep.SelectedBook = myBook.Id;
  }
  </code></pre>
  
  <p>I originally had the listview populated with buttons (that is my preference) but the SelectedItem property of ListView didn't seem to be utilized when I did this. I tried using the Clicked property of Button but couldn't find a way to obtain the Id for the selected book in this way. Am I doing something incorrectly or is there a better way to go about doing this?</p>