user6038288
user6038288

Reputation:

Multi selection in spinner

I created a 2 spinners and I need to enable users to select multiple things from each of them. I manage to add checkbox via android.R.layout.simple_list_item_multiple_choice. Now i manage to get everything that I wanted but problem is how can I enable user to select multiple things there are already check boxes but when user click on some item it immediately close spinner and stay selected on that item.

This is the design that I get and that I want but problem is with selection.

http://pokit.org/get/?1c872c5becdeb79b792617fc870f1da4.jpg This is selection: http://pokit.org/get/?e892ee2f941ab3f98b8ee51e6f9e8fc6.jpg

This is my current code for that spinner:

 public void onViewCreated(View view, Bundle savedInstanceState) {
    Spinner placesspinner=(Spinner)getActivity().findViewById(R.id.spinner_locations);
    Spinner catspinner=(Spinner)getActivity().findViewById(R.id.spinner_category);
    ArrayAdapter<String> adp1=new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_multiple_choice,places);
    placesspinner.setAdapter(adp1);
    catspinner.setAdapter(adp1);
    // Setup any handles to view objects here
    // EditText etFoo = (EditText) view.findViewById(R.id.etFoo);
}

Upvotes: 1

Views: 7291

Answers (1)

Srinivasan
Srinivasan

Reputation: 4661

By default Spinner control is in Single Choice selection mode.

What you done is you just changed the Layout to show the spinner item with Checkbox. which doesn't mean you are showing an muti selection spinner control.

You can refer any below mentioned sample to implement multi select spinner.

multi-select-drop-down-list

android-spinner-like-ui-for-selecting-multiple-options

spinner-with-multiple-selectiondescription here

Upvotes: 3

Related Questions