2015-11-03 96 views
1
//code to dislplay item in list view 
      myList= controller.searchprop(prop_no.getText().toString()); 
      if (myList.size() != 0) { 
       ListView lv = getListView(); 
       ListAdapter adapter = new SimpleAdapter(Search_Equipments.this, myList, 
         R.layout.searchview, new String[]{"old_prop", "new_prop", "serial_no", "item_name","responsibility_center"}, new int[]{ 
         R.id.txtsearch_old_prop, R.id.txtsearch_new_prop, R.id.txtsearch_serial_no, R.id.txtsearch_item_name, R.id.txtsearch_center}); 
       setListAdapter(adapter); 

       InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
       inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); 
      }else { 
       Toast.makeText(Search_Equipments.this,"No Records Available, Please enter valid value", Toast.LENGTH_LONG).show(); 
      } 

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

      HashMap<String,String> map =(HashMap<String,String>)lv.getItemAtPosition(position); 
      //Cursor c = (Cursor) parent.getItemAtPosition(position); 
      String prop = map.put(DBController.prop_no1); 

      //String prop = String.valueOf(parent.getItemAtPosition(position - 1)); 
      Toast.makeText(Search_Equipments.this, prop, Toast.LENGTH_LONG).show(); 
     } 
    }); 

有人可以幫助我如何在點擊後從列表視圖中獲取特定數據。或者調試我的代碼。謝謝:) 有人可以幫助如何在點擊後從列表視圖中獲得特定數據。或者調試我的代碼。謝謝:)如何從列表視圖中獲取特定列值點擊該列表視圖中的一行

回答

0

有可能是更優雅的解決方案,但我最近碰到這個問題(我是新來的android開發),並提出了一個解決方案。

在您onItemClick()監聽器,將下面的代碼視圖中訪問數據:

//invoke a HashMap of the item at the given position using Parent. 
HashMap<String, String> info = (HashMap<String, String>) parent.getItemAtPosition(position); 

//Then access individual data items within the hash map using the key 
String personName = info.get("first_name"); 

//Or change data within the hash map 
info.put("first_name", "new first name"); 

我希望這回答了你的問題(如果我理解正確的話)。

相關問題