2011-09-21 92 views

回答

5

參數View v本身就是行視圖。通過調用v.getTag()獲取附加數據應該使用適配器的getView早期設置v.setTag(Object)

+0

這個例子:http://saigeethamn.blogspot.com/2010/04/custom-listview-android-developer.html。 custom_row_view.xml上有3個textview ID。使用onListItemClick時,一個位置listitem內有3行數據。如何提取這些數據?如何使用ID? – conanlive

+1

您可以使用'findviewbyId'並獲取附加到視圖的標籤。 – Ronnie

0

取決於數據的種類例如,id確實包含數據庫錶行中的_id,該行使用CursorAdapter之一設置。通常這是該數據庫表格行的PK。

0
listView.getAdapter().getItemAt(position) 

讓你綁定到視圖V

0

我想建議你不要從視圖獲取數據的對象,而不是使用您所使用的數據集到ListView的適配器ArrayList中。

在你指出的例子中,你使用了一個HashMap的ArrayList。舉個例子..

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); 
    } 
}); 
相關問題