Android onListItemClick+;安卓

Android onListItemClick+;安卓,android,listview,Android,Listview,你能解释一下这个方法的参数吗?我不理解他们。 ListView l:定义正在发生单击事件的ListView 视图v:定义在ListView中单击的视图?因此,对于ListView,这将是包含ListView的xml,如果是自定义ListView,则是包含行的xml int position:视图在列表中的位置。可以使用下面的函数检索它吗getListView().getPositionForView((LinearLayout)v.getParent()) 长id:单击的项目的行id。这与位置

你能解释一下这个方法的参数吗?我不理解他们。

ListView l
:定义正在发生单击事件的ListView

视图v
:定义在ListView中单击的视图?因此,对于ListView,这将是包含ListView的xml,如果是自定义ListView,则是包含行的xml

int position
:视图在列表中的位置。可以使用下面的函数检索它吗<代码>getListView().getPositionForView((LinearLayout)v.getParent())

长id
:单击的项目的行id。这与
位置不同吗?还是我们提供R.id.Textview?

很简单

ListView l-->是正在单击的ListView对象的名称。(简单)

视图v--->列表视图中可以有多个视图。因此,这表明哪个视图已被单击,并相应地采取行动

位置-->视图在列表中的位置。(查看位置)


id--->项目的行id。(项目ID)

1-您定义的第一个ListView对象:

ListView foo = (ListView) findViewbyId(R.id.foo);
2秒行项目本身(视图v)一个是简单的,即您单击的对象(您可以获得已单击的视图),您可以更改颜色、内容或任何您想要的内容

ListView中(视图v)对象的3位置索引从0开始


4-项目的行id(我从未使用过)

列表视图由小项目/行组成。在使用自定义listView时。每一行/项目可以具有不同的功能和布局。因此,对于每一行/项目,我们必须使用不同的功能

例如,在第四行的listview中有一个按钮,而在所有其他项目上只有文本。因此,为了将事件放在那里,您必须获取特定的行/项内容。下面的代码允许您访问单个项目

 onListItemClick(ListView l, View v, int position, long id) 


first parameter is parent where the click happened

second parameter is single View(child/row) of a ListView(Parent)

third parameter is the position of child view.

fourth parameter is the id of the child view.

Soumil Deshpande那么我们如何获得已单击的视图呢?GetSelectEditePosition()阅读此
ListView foo = (ListView) findViewbyId(R.id.foo);
 onListItemClick(ListView l, View v, int position, long id) 


first parameter is parent where the click happened

second parameter is single View(child/row) of a ListView(Parent)

third parameter is the position of child view.

fourth parameter is the id of the child view.