2015-11-03 95 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"); 

我希望这回答了你的问题(如果我理解正确的话)。