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