gpt4 book ai didi

android - Android 中的 HashMap

转载 作者:行者123 更新时间:2023-11-30 04:12:09 26 4
gpt4 key购买 nike

我在我的应用程序中使用微调器,因为我正在使用哈希表。如果用户从微调器数组中选择一个条目,则该条目的相应键值应该传递到另一个屏幕。请任何人帮助我。

我的代码:

ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();
Spinner spinner1=(Spinner)findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this,R.array.Source, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
HashMap hm = new HashMap();
hm.put("Chennai","123");
menuItems.add(hm);
spinner1.setAdapter(adapter);

最佳答案

尝试替换这段代码

 HashMap hm = new HashMap(); 
hm.put("Chennai","123");

HashMap<String, String> hm = new HashMap<String, String>(); 
hm.put("Chennai","123");

关于android - Android 中的 HashMap ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10680057/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com