I have a spiner and I want set a key and a value on this,I use of HashMap,It\'s work,but show one row,like this:
Use a LinkedHashMap and store the "strings that you want to display in the spinner" as the keys and the object that you would like to retrieve based on the spinner selection as the values . For eg. , for some reason you have a Float datatype associated with the spinner items , use:
LinkedHashMap aMap = new LinkedHashMap<>(10);
Then for the spinner , we can set the values as :
ArrayList values = new ArrayList<>(aMap.keySet());
ArrayAdapter adapter = new ArrayAdapter(getContext(), android.R.layout.simple_spinner_item,values);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Finally , in the OnItemSelectedListener , retrieve the float value as:
@Override
public void onItemSelected(AdapterView> adapterView, View view, int i, long l) {
aMap.get(adapterView.getItemAtPosition(i));
}