【问题标题】:my spinner and how to get the position of item selected我的微调器以及如何获取所选项目的位置
【发布时间】:2012-11-16 21:09:43
【问题描述】:

我有一个由数组列表填充的微调器,在微调器上的每个“梯级”的每个索引处都有多个哈希图。所以当项目被选中时,我想得到被选中的单个键并用它做一些事情 我在我的照片中确实喜欢这个,但有一个问题 我该如何解决它

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

这是一个可用的代码副本:

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) {}
});

【问题讨论】:

    标签: android


    【解决方案1】:

    您必须一次完成一个级别。首先从您的 ArrayList 中获取每个 HashMap,然后询问您的特定密钥:

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

    但是,如果您刚刚初始化 arrList,则其中不会有任何内容...

    【讨论】:

    • 谢谢,但我确实喜欢 spinner2.setOnItemSelectedListener(new CustomOnItemSelectedListener() { 那么我在 CustomOnItemSelectedListener 做什么?同样的或
    • 因为这个问题严格来说是关于从每个 HashMap 中获取特定值。让我们讨论在your previous question 中使用哪个监听器。
    • 好吧,我照你说的做,我试着改变我的代码,你能帮我吗
    • 我刚刚在另一个问题中发布了答案。在那里见。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-20
    相关资源
    最近更新 更多