HashMAp in android

I am using spinner in my application,in that i am using a hashtable.In that if user selects an entry from Spinner array the corresponding key value of that entry should be passed to another screen.Please anybody help me.

My Code:

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

Answers


Try by replacing this code

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

with

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

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.


Need Your Help

Navigation working very slow

ios objective-c uinavigationcontroller

On working with a navigation based application performing 3-4 push.

Django Nonrel - Can't log into Admin Panel on development server

python django django-admin django-nonrel

Bit of a strange one. I've created a super user for django admin for my app, which is just a new django nonrel project with admin enabled. I try and access the /admin whilst running the development