![](https://camo.githubusercontent.com/21ebf67f54e29cc494b074a8f800b5281e9f3be2d77347fbb09781b6c4b1a4fd/68747470733a2f2f6a69747061636b2e696f2f762f70726174696b627574616e692f4d756c746953656c6563745370696e6e65722e737667)
How to import (Add dependency in build.gradle):
compile 'com.github.pratikbutani:MultiSelectSpinner:08d324c987'
- Made this an Android Studio project.
- Added Material library.
- Extracted the sample into a separate module.
- Code cleanup.
MultiSelect Spinner with Search/Filter:
![](https://camo.githubusercontent.com/d1b967b6f0399edfba3bb1670507e9e7a276281a0f5f2c73fe79d94bdc92827a/68747470733a2f2f6c68352e676f6f676c6575736572636f6e74656e742e636f6d2f2d4d69766c48304478684d632f565a4a39314161367174492f41414141414141414c64632f5a596648426f5f6539566b2f773332352d683537372d6e6f2f53637265656e73686f745f323031352d30362d33302d31362d30332d35392e706e67)
![](https://camo.githubusercontent.com/845820d0e2f09ebe663ee6830dc8b30004a30417bfd5ee87fc9bc3e1bb491595/68747470733a2f2f6c68352e676f6f676c6575736572636f6e74656e742e636f6d2f2d6f4c55385a7a737858426b2f565a4a3931525a634769492f41414141414141414c646f2f72344c67766154423570382f773332352d683537372d6e6f2f53637265656e73686f745f323031352d30362d33302d31362d30332d35312e706e67)
How to use (WITHOUT FILTER):
/*
* Getting array of String to Bind in Spinner
*/
final List<String> list = Arrays.asList(getResources().getStringArray(R.array.sports_array));
/**
* Simple MultiSelection Spinner (Without Search/Filter Functionlity)
*
* Using MultiSpinner class
*/
MultiSpinner simpleSpinner = (MultiSpinner) findViewById(R.id.simpleMultiSpinner);
simpleSpinner.setItems(list, "Multi Selection Without Filter", -1, new MultiSpinnerListener() {
@Override
public void onItemsSelected(boolean[] selected) {
// your operation with code...
for(int i=0; i<selected.length; i++) {
if(selected[i]) {
Log.i("TAG", i + " : "+ list.get(i));
}
}
}
});
How to use (WITH FILTER):
/**
* Search MultiSelection Spinner (With Search/Filter Functionality)
*
* Using MultiSpinnerSearch class
*/
MultiSpinnerSearch searchSpinner = (MultiSpinnerSearch) findViewById(R.id.searchMultiSpinner);
final List<KeyPairBoolData> listArray = new ArrayList<KeyPairBoolData>();
for(int i=0; i<list.size(); i++) {
KeyPairBoolData h = new KeyPairBoolData();
h.setId(i+1);
h.setName(list.get(i));
h.setSelected(false);
listArray.add(h);
}
/***
* -1 is no by default selection
* 0 to length will select corresponding values
*/
searchSpinner.setItems(listArray, "Multi Selection With Filter", -1, new MultiSpinnerSearchListener() {
@Override
public void onItemsSelected(List<KeyPairBoolData> items) {
for(int i=0; i<items.size(); i++) {
if(items.get(i).isSelected()) {
Log.i("TAG", i + " : " + items.get(i).getName() + " : " + items.get(i).isSelected());
}
}
}
});
/**
* Using MultiSpinnerSearch object
* call setLimit method
*
*/
searchSpinner.setLimit(3, new MultiSpinnerSearch.LimitExceedListener() {
@Override
public void onLimitListener(KeyPairBoolData data) {
Toast.makeText(getApplicationContext(),
"Limit exceed ", Toast.LENGTH_LONG).show();
}
});