// template class to create list item objects
class MyListItem{
public String name;
public long dbId;
public MyListItem(String name, long dbId){
this.name = name;
this.dbId = dbId;
}
}
///////////////////////////////////////////////////////////
// create ArrayList of MyListItem
ArrayList<MyListItem> myListItems = new ArrayList<MyListItem>(10);
// override BaseAdapter methods
@Override
public Object getItem(int position) {
// return actual object <MyListItem>
// which will be available with item in ListView
return myListItems.get(position);
}
@Override
public long getItemId(int position) {
// return id of database document object
return myListItems.get(position).dbId;
}
///////////////////////////////////////////////////////////
// on list item click, get name and database document id
my_list_view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
// extract item data
MyListItem selectedItem = (MyListItem)parent.getItemAtPosition(position);
System.out.println("Your name is : " + selectedItem.name);
// extract database ref id
long dbId = id;
// or you could also use
long dbId = parent.getItemIdAtPosition(position);
}
});