I have this piece of code for listview using simple cursor adapter :
final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), R.layout.textonly_listview_item, cursor, from, to);
listview.setAdapter(adapter);
listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Cursor item = (Cursor) parent.getItemAtPosition(position);
adapter.notifyDataSetChanged();
view.setSelected(true);
G.t(getActivity(), "Now working with category: " + item.getName());
}
});
when clicked whichever cell, it always get the first item or the top most item in list view, can some one tell me where i am wrong?
As mentioned in the comment, you should move the adapter.notifyDataSetChanged();
to the end. That is the probable reason why this happens.