Upload Empty Spinner

1

When generating a Spinner , it returns the first value of the ArrayList generated already selected.

How do I bring it "empty"?

The best option would be to populate it with a onClick function instead of doing it in onCreate , for example?

    
asked by anonymous 25.01.2018 / 16:07

1 answer

2

You can add an empty field before popular with the array, this same index being 0 you can also use as validation if the user has not selected any options.

Example:

ArrayList<String> meuArray = new ArrayList<>();
meuArray.add("");

//Popular array
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        if (position == 0)
            //Não selecionou
        else
            //Selecionou
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
});

I hope it helps.

    
25.01.2018 / 16:33