Android AdapterView Click Listener Parameters - position & id

后端 未结 2 1271
时光取名叫无心
时光取名叫无心 2021-01-15 16:54

I\'m setting a long click listener on a listview and I want to use the index of the clicked item to retrieve the corresponding object.

Method signature and paramete

2条回答
  •  深忆病人
    2021-01-15 17:14

    ID is the id from the database (i.e. _ID). position is the position in the Array or ArrayList.

    For example: if you have in your DB records with IDs 1,2,3,4 and you use SQL to retrieve the records (and populate the array or ArrayList) you may have some filter (where clause) and show just elements with IDs 1 and 3. That way you have just 2 possible positions - 0 and 1.

    The difference is: you may think for row ID as some external ID, that belongs to data row itself. In contrary position "belongs" to the list view and it's adapter.

提交回复
热议问题