tiper / MaterialSpinner

Implementation of a Material Spinner for Android with TextInputLayout functionalities
Apache License 2.0
130 stars 30 forks source link

Allow choose "none" #5

Closed petr-stety-stetka closed 5 years ago

petr-stety-stetka commented 5 years ago

Hi,

Is some easy way, how select "none" in spinner? Thanks!

Petr

tiper commented 5 years ago

Hi @petr-stety-stetka you can setSelection(-1) which will clear the value and invoke the onNothingSelected from the callback.

Take a look at the provided sample as example.

petr-stety-stetka commented 5 years ago

I think some better UI solution than separrate button for clearing, for example empty first item in dropdown.

tiper commented 5 years ago

You can easily achieve that behaviour by providing a clear option as one of the possible selections from the spinner. On the callback onItemSelected if the position is the position of the clear option you just call setSelection(-1) on the spinner.

For example:

JAVA:

if (position == 0) {
    spinner.setSelection(-1);
}

Kotlin:

if (position == 0) {
    spinner.selection = -1
}