0

I have a ListView populated with hardcoded data from an ArrayList. The list contains Person objects.

I have successfully got them to display in the list and assigned a listener to each item. What I am trying to do is add the selected item to an ArrayList called employees.

protected void onListItemClick(listView l, View v, int position, long id){

     Person p = l.getItemAtPosition(position);
     employees.add(p);
}

I am aware the above code will not work as the getItemAtPosition returns a long value. However is there a way I can work with this value to create a person object to hold the item clicked by the user?

So basically I have a ListView populated by data in ArrayList people.

ArrayList<Person> people;

I then want to addthe item clicked by the user into an ArrayList employee.

ArrayList<Person> employee;
Javacadabra
  • 5,578
  • 15
  • 84
  • 152
  • 1
    Not the same question but the answer will work, too: http://stackoverflow.com/questions/6562236/android-spinner-databind-using-array-list/6562433#6562433 – Lukas Knuth Dec 08 '12 at 14:54
  • He is using Casting right? that is exactly what I needed! I'll give that a try. Thanks very much. – Javacadabra Dec 08 '12 at 14:58

0 Answers0