【问题标题】:how to get a particular column value from a list view on click of a row from that list view如何在单击列表视图中的行时从列表视图中获取特定列值
【发布时间】:2015-11-03 08:47:18
【问题描述】:
//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();
        }
    });

点击后,有人可以帮助如何从列表视图中连续获取特定数据。或调试我的代码。谢谢 :) 有人可以帮助我单击后如何从列表视图中连续获取特定数据。或调试我的代码。谢谢:)

【问题讨论】:

    标签: android sqlite android-studio


    【解决方案1】:

    可能有更优雅的解决方案,但我最近遇到了这个问题(我是 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");
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多