之间的位置和行ID实用性差的onListItemClick()实用性、位置、ID、onListItemClick

2023-09-13 00:40:49 作者:等一个旧人

我感到困惑的 ListActivity 现在的位置行ID 之间的差异。 onListItemClick()

该文件有以下几点:

 的位置来看,在列表中的位置
该项目的ID行ID被点击
 

时两者之间有任何实际的区别?我认为,因为有两个不同的参数,有其中的值不同的情况,但基于文档中使用的措辞,很难看到这种差异可能。它是其中一人可以持有一个光标或其他一些特殊的能力?

提供了一个数据库行的ID值 解决方案   

位置:视图中的列表 - 位置    ID :被点击的项目的行ID

一个位置,从0开始,顶到ListView的底部,而得到一个合适的行ID重要的是,这是传递给适配器游标包含一行称为_id重presenting唯一id每行中的表

如何查看自己电脑的ID

如果您使用的是arrayAdapter 位置 ID 成为相同的。该ID将 Adapter.getItemId(INT)因此,如果您使用ArrayAdapter这将是相同位置的返回值 - 快速搜索 ArrayAdapter 源$ C ​​$ C说明它是一个使用返回位置;制定出ID。

I'm confused about the difference between postion and row id in ListActivity.onListItemClick().

The documentation has the following:

position  The position of the view in the list
id        The row id of the item that was clicked

Is there any practical difference between the two? I assume, since there are two different parameters, that there are situations where the values are different, but based on the wording used in the documentation, it's hard to see what that difference may be. Is it that one of them can hold the value of a database row ID provided by a Cursor or some other special capability?

解决方案

position: The position of the view in the list id: The row id of the item that was clicked

A position starts from 0 , top to bottom of the ListView, whereas to get a proper row id it is important that the cursor which was passed to the adapter contains a row called '_id' representing unique id for each row in the table.

If you are using an arrayAdapter position and id became the same. The id will be the returned value of Adapter.getItemId(int) so if you use an ArrayAdapter it will be the same as the position - a quick search of the ArrayAdapter source code shows it's using return position; to work out the id.