2011-08-10 5 views
0

Je l'ai fait Muticolum ListView onListItemClick .Son travail fine.Problem estAndroid Muticolum listview onListItemClick

Cette ligne String selection = l.getItemAtPosition(position).toString(); retour ce {routeName=TestRoute2, outlets=5, routeCode=VRT002} .Je veux obtenir 3ème colonne de ligne sélectionnée value.How pour l'obtenir.

S'il vous plaît aidez-moi ..

Merci à l'avance ..

Répondre

1

Quel type d'adaptateur? Par exemple. pour un SimpleCursorAdapter vous procédez comme suit:

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

J'utilise 'SimpleAdapter' – Piraba

+1

Vous avez donc introduit une HashMap dans ListView? Vous obtiendrez HashMap hashMap = (HashMap ) listView.getItemAtPosition (position); à l'époque. –

+0

Ceci est la bonne réponse.Merci son fonctionnement bien – 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); 

      } 
     }); 

Dans le code ci-dessus le contenu ListView sont peuplés en utilisant un ArrayList historyArrayList et ainsi les éléments à une colonne pouvait accéder en utilisant la clé ("AssetTag "," gif "," action "," actionTime ").

Questions connexes