Search code examples
androidnumberpicker

Android - Update string based numberpicker on the fly as user enters data


I built a string based numberPicker with all country names, and an editText to function as a search field. I want the numberPicker to refresh\update itself according to what letters the user enters to the search editText. I.E suppose the user types in the letter "I", the picker should show the first country that starts with the letter "I", and update its results according to the rest of the string, like it shows suggestions.

editTextCountryInput = (EditText) findViewById(R.id.editTextCountryInput);
String[] countriesForPicker = new String[236];//array with all countries names

//this fills the country picker with names
    private void generateCountryPicker() {
            picker.setMinValue(0);
            picker.setMaxValue(countriesForPicker.length()-1);
            picker.setDisplayedValues(countriesForPicker);
        }

Is there any way of doing it?


Solution

  • Posting as an answer so you can close this out*.

    You should be able to use a text changed listener like this guy: Android: On EditText Changed Listener

    *I'm not too concerned about the points, I just prefer it when people can tell the question has been answered