Reputation: 161
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);
Upvotes: 1
Views: 901
Reputation: 6973
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");
Upvotes: 1
Reputation: 6836
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.
Upvotes: 0