简体   繁体   中英

my spinner and how to get the position of item selected

i have a spinner populated by an arraylist with multiple hashmaps at each index for each "rung" on the spinner. So when the item is selected, i want to get the single key that is selected and do something with it i do like this in my pic but there is a problem how can i solve it

image http://www.qzal.net/01/2012-10/13530999521.png

Here is a usable copy of the code:

spinner2.setOnItemSelectedListener(new CustomOnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
        ArrayList<HashMap<String, String>> arrList = new ArrayList<HashMap<String,String>>();
        // for each key in the hashMap at this position..
        for (String key : arrList.get(position).get("SectionID"))
        {
        }
    }                                      

    @Override
    public void onNothingSelected(AdapterView<?> adapter) {}
});

You must do this one level at a time. First fetch each HashMap from your ArrayList, then ask for your specific key:

for (HashMap<String, String> map : arrList) {
    String value = map.get("SectionID");
    // Do something
}

However if you just initialized arrList there won't be anything in it...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM