2011-08-10 35 views
0

我已經做了Muticolum列表視圖onListItemClick。其工作fine.Problem是的Android Muticolum列表視圖onListItemClick

此行String selection = l.getItemAtPosition(position).toString();返回此 {routeName=TestRoute2, outlets=5, routeCode=VRT002}。我想要得到它選定行的第三列value.How得到它。

請幫助我..

在此先感謝..

回答

1

什麼樣的適配器?例如。對於SimpleCursorAdapter你會做到以下幾點:

Cursor cursor = (Cursor) listView.getItemAtPosition(position); 
long aLongValue = cursor.getLong(cursor.getColumnIndexOrThrow("anintegercolumn")); 
+0

我正在使用'SimpleAdapter' – Piraba

+1

所以你已經將一個HashMap提供給ListView?您將獲得HashMap hashMap =(HashMap )listView.getItemAtPosition(position);那時候。 –

+0

這是正確答案。謝謝它的正常工作 – Piraba

1
ArrayList<HashMap<String, String>> historyArrayList; 
SimpleAdapter histroyListAdapter; 

HashMap<String, String> historyObjectMap; 

for (CheckInCheckOutHistory checkOutHistoryObj : checkInCheckOutHistoryList) { 
    historyObjectMap = new HashMap<String, String>(); 
     historyObjectMap.put("assetTag", checkOutHistoryObj.getAssetTag()); 
     historyObjectMap.put("action", checkOutHistoryObj.getAction()); 
    historyObjectMap.put("actionTime", checkOutHistoryObj.getActionDate()); 

     if (checkOutHistoryObj.getAction().equals("Checked out")) { 
      historyObjectMap.put("gif", R.drawable.radio_button_yellow+ ""); 
     } else { 
      historyObjectMap.put("gif", R.drawable.radio_button_green+ ""); 
     } 

     historyArrayList.add(historyObjectMap); 
} 

histroyListAdapter = new SimpleAdapter(
      ViewCheckInCheckOutHistory.this, historyArrayList, 
      R.layout.multi_colummn_list_text_style_small, new String[] { 
        "assetTag", "gif" , "action", "actionTime"}, 
        new int[] { R.id.list_content_column1, 
          R.id.list_content_imagecolumn, 
          R.id.list_content_column3, 
          R.id.list_content_column4}); 

     historyListView.setOnItemClickListener(new OnItemClickListener() { 

      @Override 
      public void onItemClick(AdapterView<?> parent, View view, 
        int position, long id) { 

       HashMap<String, String> historyObjectMapLocal = historyArrayList 
            .get(position); 
       final String assetTag = historyObjectMapLocal 
            .get("assetTag"); 

       System.out.println("assetTag : " + assetTag); 

      } 
     }); 

在上面的代碼ListView的內容是使用一個ArrayList historyArrayList 並因此在任何列中的項目可以使用鍵來訪問(「ASSETTAG填充「,」gif「,」動作「,」動作時間「)。