title: Getting custom object on click from ListView
body: <p>I'm displaying a ListView that I filled with a custom ListAdapter, called LazyAdapter, which code comes from here : <a href="http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/" rel="nofollow noreferrer">http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/</a>. The LazyAdapter uses my custom objects "EventData". I managed to display my List as I wanted, but now I'd like to get the clicked object. I found some help on other questions (<a href="https://stackoverflow.com/questions/10275911/accessing-custom-objects-in-a-listview">here</a>, <a href="https://stackoverflow.com/questions/4508979/android-listview-get-selected-item">here</a>, and <a href="https://stackoverflow.com/questions/4834750/how-to-get-the-selected-item-from-listview">there</a>), and wrote that code: </p>
  
  <pre><code>private OnItemClickListener mEventClickListener = new OnItemClickListener() {
      @Override
      public void onItemClick(AdapterView&lt;?&gt; av, View v, int arg2, long arg3) {
  
          EventData selectedEvent = (EventData) eventsListView.getItemAtPosition(arg2);
  
  };
  </code></pre>
  
  <p>However, I get a cast error at execution. </p>
  
  <pre><code>05-14 17:10:46.718: E/AndroidRuntime(3863): java.lang.ClassCastException: java.lang.Integer
  </code></pre>
  
  <p>I also tried this similar solution:</p>
  
  <pre><code>EventData selectedEvent = (EventData) av.getItemAtPosition(arg2);
  </code></pre>
  
  <p>I got the same cast error. I don't know how I can get my Object EventData in an other way.</p>
  
  <p>Thanks for your help!</p>