I have a SeperatedListAdapter with 2 sections and each section having 6 items in it.
Code:
listView.setAdapter(adapter);
listView.setOnItemClickListener(listViewListener);
Adding section headers and items in this fashion:
adapter = new SeparatedListAdapter(this);
adapter.addSection(entry.getKey(), new ItemAdapter(this, 0, topics.toArray(array)));
OnItemClickListener listViewListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long duration) {
Employee emp = emps.get(position - 1);
}
};
I have ArrayList as:
items from section 1
Anand - 0
Sunil - 1
Suresh - 2
Dev - 3
Faran - 4
Khan - 5
items from section 2
Samba - 6
Surendra - 7
Rajesh - 9
Rakesh - 10
Satish - 11
Now in OnItemClickListener
when I get the position, it's also taking the section header as position.
So I did it as Employee emp = emps.get(position - 1);
but up to 6 items (0-5 from my arraylist) is fine but after that the position is not proper. How can I solve this issue?
I need to pass the postion to my Arrray list in this fashion
Employee emp = emps.get(position - 1);
since I will be passing the employee object to another class.
see this too:
Android - SeparatedListAdapter - How to get accurate item position on onClick?