Searchable Spinner not working in android
04:13 27 Oct 2017

I had a simple spinner which i working perfect. Now I wanted to change it that a user can able to search the items in it. By following the below code I have done changes.

Sample code

//Gradle

 compile 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'

//activity_main.xml

 
// In main activity 

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    SearchableSpinner searchableSpinner = (SearchableSpinner) findViewById(R.id.searchable_spinner);
    String[] names = new String[]{"India","CHINA","UK","US","MALYSIA"};
    ArrayAdapter arrayAdapter = new ArrayAdapter(MainActivity.this,android.R.layout.simple_spinner_dropdown_item,names);
    searchableSpinner.setAdapter(arrayAdapter);

    searchableSpinner.setTitle("Select Item");
    searchableSpinner.setPositiveButton("OK");

}

Output

On click of the dropdown

enter image description here

What i have done?

//added the library in gradle 
compile 'com.toptoche.searchablespinner:searchablespinnerlibrary:1.3.1'

//new_form_layout (i have created this)


**In My Fragment**
@BindView(R.id.smart_msn_spinner)
SearchableSpinner smartMsnSpinner;

Now I have created a bindListners() function in which I am binding all the values and I am calling it in my onCreateView function

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (view == null) {
        view = inflater.inflate(R.layout.new_form_layout, container, false);
        ButterKnife.bind(this, view);
        bindListners(); // here i am calling it
        imsiNo.setVisibility(View.GONE);
        setupUI(mScrollView);
    }
    Bundle arguments = getArguments();
    if (arguments != null && arguments.containsKey("install_id")) {
        isNewInstall = false;
        editInstallId = arguments.getString("install_id");
        getActivity().setTitle(getString(R.string.title_fragment_edit_form));
        setEditData();
        imsiNo.setVisibility(View.GONE);
        resetFormButton.setVisibility(View.GONE);
    } else {
        getActivity().setTitle(getString(R.string.title_fragment_new_form));
    }

    /*mCoordinatesReceiver = new CoordinatesReceiver();
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Common.GetCoordinatesAction());
    getActivity().registerReceiver(mCoordinatesReceiver, intentFilter);*/
    return view;
}
bindListeners(){
.......

    //Searchable smartMsnSpinner spinner and adapter
    meterSrArrayList = new ArrayList();

    meterSrNumAdapter = new ArrayAdapter(getActivity(), R.layout.custom_spinner_layout, meterSrArrayList);
    smartMsnSpinner.setAdapter(meterSrNumAdapter);
    smartMsnSpinner.setTitle("Select Item");
    smartMsnSpinner.setPositiveButton("Ok");
    smartMsnSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView parent, View view, int position, long id) {
            selectedMeterNo = meterSrArrayList.get(position);
        }

        @Override
        public void onNothingSelected(AdapterView parent) {

        }

    });
 }

On running my app i am just getting simple drop down list as before.

enter image description here

I don't know what is the problem and what I am missing as i have done everything that is in the sample.

I have run the sample code in my device and it's working fine. I don't know why it's not working on my app

Update

After watching the logcatthe error i am seeing is

Parcelable encountered IOException writing serializable object (name = com.toptoche.searchablespinnerlibrary.SearchableSpinner)

Any help would be highly appreciated.

android android-fragments android-arrayadapter android-spinner searchable