I´ve made quite many listeners and never really thought of it until now.
Basic Listview listener:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "you clicked on: " + position + " id: " + id, Toast.LENGTH_SHORT).show();
}
});
According to documentary:
position is: The position of the view in the adapter.
id is: The row id of the item that was clicked.
Could someone good-hearted explain the difference for me.
Thx in advance..
According to the docs
position The position of the view in the adapter.
id The row id of the item that was clicked.
The position is the position of the view inside the parent. For your case (a ListView
) it means the index of the row. (Starting at 0) For ArrayAdapter
and SimpleAdapter
id is the same as position. For a CursorAdapter
, id is the row id of the table.
Related Answers:
Practical Difference Between position and row id in onListItemClick()
https://stackoverflow.com/a/25622142/2278598
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With