请问如何从Android ListView中的价值? [英] how do i get the value from the android listview?

查看:106
本文介绍了请问如何从Android ListView中的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code我要访问的 KEY_ID ,我把在MAPLIST列表项单击一个变量..
请帮助我,我怎么能做到这一点。

 的ArrayList(HashMap的)(字符串,字符串)MAPLIST =新的ArrayList(的HashMap(字符串,字符串))();
    XMLParser的解析器=新XMLParser的();
    文档的文档= parser.getDomElement(XML);
//获得DOM元素
    节点列表NL = doc.getElementsByTagName(KEY_Route);    //遍历所有歌曲节点&LT循环;宋>
    的for(int i = 0; I< nl.getLength();我++){
        //创建新的HashMap
        HashMap的<字符串,字符串>地图=新的HashMap<字符串,字符串>();        元素e =(元)nl.item(I)        //将每个子节点的HashMap键=>值        map.put(KEY_ID,parser.getValue(即KEY_ID));
        map.put(KEY_SchoolName,parser.getValue(即KEY_SchoolName));
        map.put(KEY_ChildrenName,parser.getValue(即KEY_ChildrenName));
        map.put(KEY_AlertTime,parser.getValue(即KEY_AlertTime));
        map.put(KEY_RouteName,parser.getValue(即KEY_RouteName));
        map.put(KEY_Notification,parser.getValue(即KEY_Notification));
        map.put(KEY_StopName,parser.getValue(即KEY_StopName));
        //添加HashList到ArrayList的
        mapList.add(地图);
    }    名单=(ListView控件)findViewById(R.id.list);    //通过传递XML数据的ArrayList获取适配器
    适配器=新LazyAdapter(这一点,MAPLIST);
    list.setAdapter(适配器);    // Click事件的单排列表
    list.setOnItemClickListener(新OnItemClickListener(){        @覆盖
        公共无效onItemClick(适配器视图<>母公司,观景,
                INT位置,长的id){
            INT IDW =位置;
            长logss = ID;//在那里,我要访问的KEY_ID ..            }赶上(例外五){
                e.printStackTrace();
                progressDialog.dismiss();
            }        }
    });
}


解决方案

在您的 onItemClick 方式,你需要获取的 HaspMap 的出离的 MAPLIST 从特定对象的位置的:

 的HashMap<字符串,字符串>地图= mapList.get(位置);//然后从地图对象读出值

Hi this is my code i want to access the KEY_ID that i put in maplist on list item click in a variable.. Please Help me How i can do this.

ArrayList (HashMap)  (String, String) mapList = new ArrayList(HashMap(String, String)) ();
    XMLParser parser = new XMLParser();
    Document doc = parser.getDomElement(xml); 
// getting DOM element
    NodeList nl = doc.getElementsByTagName(KEY_Route);

    // looping through all song nodes <song>
    for (int i = 0; i < nl.getLength(); i++) {
        // creating new HashMap
        HashMap<String, String> map = new HashMap<String, String>();

        Element e = (Element) nl.item(i);

        // adding each child node to HashMap key => value

        map.put(KEY_ID, parser.getValue(e, KEY_ID));
        map.put(KEY_SchoolName, parser.getValue(e, KEY_SchoolName));
        map.put(KEY_ChildrenName, parser.getValue(e, KEY_ChildrenName));
        map.put(KEY_AlertTime, parser.getValue(e, KEY_AlertTime));
        map.put(KEY_RouteName, parser.getValue(e, KEY_RouteName));
        map.put(KEY_Notification, parser.getValue(e, KEY_Notification));
        map.put(KEY_StopName, parser.getValue(e, KEY_StopName));
        // adding HashList to ArrayList
        mapList.add(map);
    }

    list = (ListView) findViewById(R.id.list);

    // Getting adapter by passing xml data ArrayList
    adapter = new LazyAdapter(this, mapList);
    list.setAdapter(adapter);

    // Click event for single list row
    list.setOnItemClickListener(new OnItemClickListener() {

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

// There i want to access the KEY_ID..              

            } catch (Exception e) {
                e.printStackTrace();
                progressDialog.dismiss();
            }

        }
    });
}

解决方案

In your onItemClick method, you need to fetch HaspMap out from mapList object from a specific position:

HashMap<String, String> map = mapList.get(position);

//and then read values out from 'map' object

这篇关于请问如何从Android ListView中的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆