As you mensiond in you comment you are using the Separating Lists with Headers in Android 0.9 example.
So there is a method into adpater,
public Object getItem(int position) {
for(Object section : this.sections.keySet()) {
Adapter adapter = sections.get(section);
int size = adapter.getCount() + 1;
// check if position inside this section
if(position == 0) return section;
if(position < size) return adapter.getItem(position - 1);
// otherwise jump into next section
position -= size;
}
return null;
}
which returns the correct item.
So you only need to call this method, into OnItemClickListener
like
OnItemClickListener listViewListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long duration) {
Employee emp = (Employee) adapter.getItem(position); // HERE is the code to get correct item.
}
};
Add below method to SeparatedListAdapter
public Employee getItem(int position, ArrayList<Employee> lists) {
for(Object section : this.sections.keySet()) {
Adapter adapter = sections.get(section);
int size = adapter.getCount() + 1;
// check if position inside this section
if(position == 0) return lists.get(position);
if(position < size) return lists.get(position - 1);
// otherwise jump into next section
position -= size;
}
return null;
}
and call it as
Employee emp = adapter.getItem(position, emps);