简体   繁体   English

如何在列表视图中获取行视图数据

[英]How to get row view data in the listview

this example: http://saigeethamn.blogspot.com/2010/04/custom-listview-android-developer.html .There are 3 textview ids at custom_row_view.xml. 此示例: http ://saigeethamn.blogspot.com/2010/04/custom-listview-android-developer.html。custom_row_view.xml中有3个textview ID。 There are 3 row data inside one position listitem when using onListItemClick. 使用onListItemClick时,一个位置列表项中有3行数据。 how to extract these data? 如何提取这些数据? how to use the id? 如何使用ID? Anyway to get row view data in the list view when the list item is clicked [protected void onListItemClick(ListView l, View v, int position, long id]? 无论如何在单击列表项时获取列表视图中的行视图数据[protected void onListItemClick(ListView l,View v,int position,long id]?

The parameter View v itself is the row view. 参数View v本身就是行视图。 You can get the attached data by calling v.getTag() . 您可以通过调用v.getTag()获得附件数据。 Should set it earlier in getView of adapter using v.setTag(Object) 应该在早期使用v.setTag(Object)在适配器的getView中进行v.setTag(Object)

I would like to recommend you not to get data from the view, instead use the ArrayList you have used to set data to the Adapter of the ListView . 我不建议您不要从视图中获取数据,而应使用用于将数据设置为ListView的Adapter的ArrayList

In the example which you have pointed out, you are using an ArrayList of HashMap. 在您指出的示例中,您正在使用HashMap的ArrayList。 So for an example.. 举个例子。

listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // arrayList is the variable which you have used as a list in your SimpleAdapter
        hashMap = arrayList.get((int)id); // you need to typecast 'id' from long to int
        value = hashMap.get(KEY);
    }
});

Depends on the kind of data. 取决于数据的种类。 For example id does contain the _id from a database table row that was set with one of the CursorAdapters. 例如,id确实包含使用CursorAdapters之一设置的数据库表行中的_id。 Usually this is the PK of that database table row. 通常,这是该数据库表行的PK。

listView.getAdapter().getItemAt(position)

让您将对象绑定到视图V

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM