1

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

我的代码:

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);
4

2 回答 2

1

尝试替换此代码

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

HashMap<String, String> hm = new HashMap<String, String>(); 
            hm.put("Chennai","123");
于 2012-05-21T06:53:05.017 回答
0
sp.setOnItemSelectedListener(new OnItemSelectedListener() {

            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                int item = sp.getSelectedItemPosition();
                Toast.makeText(getBaseContext(), 
                        "You have selected the book: " + androidBooks[item], 
                        Toast.LENGTH_SHORT).show();
            }

            public void onNothingSelected(AdapterView<?> arg0) {
            }
            
        });

in toast you get selected item pass this item to another screen.

于 2012-05-21T06:19:11.823 回答