android中的HashMAp
我在应用程序中使用spinner,因为我使用的是哈希表。如果用户从spinner数组中选择一个条目,则该条目的相应键值应传递到另一个屏幕。请任何人帮助我 我的代码:android中的HashMAp,android,hashtable,Android,Hashtable,我在应用程序中使用spinner,因为我使用的是哈希表。如果用户从spinner数组中选择一个条目,则该条目的相应键值应传递到另一个屏幕。请任何人帮助我 我的代码: ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>(); Spinner spinner1=(Spinner)findView
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);
ArrayList menuItems=new ArrayList();
喷丝器喷丝器1=(喷丝器)findViewById(R.id.spinner1);
ArrayAdapter=ArrayAdapter.createFromResource(
这个,R.array.Source,android.R.layout.simple\u微调器\u项);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
HashMap hm=新的HashMap();
hm.put(“钦奈”、“123”);
菜单项添加(hm);
喷丝头1.设置适配器(适配器);
sp.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView arg0、视图arg1、,
整数arg2,长arg3){
int item=sp.getSelectedItemPosition();
Toast.makeText(getBaseContext(),
您已选择书籍:“+androidBooks[项目],
吐司。长度(短)。show();
}
未选择公共无效(AdapterView arg0){
}
});
在toast中,您将获得所选项目
将此项目传递到另一个屏幕。sp.setOnItemSelectedListener(新的OnItemSelectedListener(){
已选择公共视图(AdapterView arg0、视图arg1、,
整数arg2,长arg3){
int item=sp.getSelectedItemPosition();
Toast.makeText(getBaseContext(),
您已选择书籍:“+androidBooks[项目],
吐司。长度(短)。show();
}
未选择公共无效(AdapterView arg0){
}
});
在toast中,您将获得所选项目
将此项目传递到另一个屏幕。尝试替换此代码
HashMap hm = new HashMap();
hm.put("Chennai","123");
与
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("Chennai","123");
HashMap hm=newhashmap();
hm.put(“钦奈”、“123”);
尝试替换此代码
HashMap hm = new HashMap();
hm.put("Chennai","123");
与
HashMap<String, String> hm = new HashMap<String, String>();
hm.put("Chennai","123");
HashMap hm=newhashmap();
hm.put(“钦奈”、“123”);
请明确您仅将哈希表用作微调器的数据源或哈希表列表。嗨,吉特和约格什·卡马利亚,我已经发布了我的代码。请明确您仅将哈希表用作微调器的数据源或哈希表列表。嗨,吉特和约格什·卡马利亚,我已经发布了我的代码。