tiper / MaterialSpinner

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

Unable to close view when materialSpinner is clicked #4

Closed Marcosmaliki closed 5 years ago

Marcosmaliki commented 5 years ago

Great job!! I always hated the default android spinner. This library is awesome but on select devices, the list_item view cannot be closed. I had to switch but I hope you can solve this.

tiper commented 5 years ago

Hi @Marcosmaliki the spinner dropdown/dialog/bottomsheet is triggered when the spinner is focused. Try to ensure that the spinner is not the only focusable view. For example you can try adding android:descendantFocusability="beforeDescendants", android:focusable="true" and android:focusableInTouchMode="true" to the spinner parent.

emersonassis commented 5 years ago

The solution proposed by @tiper saved me...

Marcosmaliki commented 5 years ago

Thank you. Works perfectly

githeyj commented 4 years ago

Hi @tiper this did not help

tiper commented 4 years ago

@githeyj Did you add the properties to the spinner itself or the parent?

sebasira commented 4 years ago

@githeyj do you happen to use a ScrollView as the top-parent layout? I was having the same problem:

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:descendantFocusability="beforeDescendants"
        android:focusable="true"
        android:focusableInTouchMode="true">

        <LinearLayout
            android:id="@+id/subItem"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <com.tiper.MaterialSpinner
                    android:id="@+id/spinner"
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:hint="@string/hint_spinner"/>

        </LinearLayout>
</ScrollView>

With this structure (I've got a lot more spinners), the focus automatically goes to the first item of the layout after I close the spinner (no matter if the first item is a Spinner or and EditText). If the first item is a Spinner I won't be able to close it, and if I click the third spinner, I can close it but it will automatically open the first one.

I wrap the ScrollView in another layout (I use a CoordinatorLayout) and now it works

divya-navsoft commented 4 years ago

Hi @tiper really awesome library you've created. I want to add country image flag and country code as fetched from api and add custom adapter in the material spinner and show it when item selected. I have successfully created the custom adapter showing bottom dialog with image flag and code but when I'm selecting one item its only text that showing in Materialspinner. please help.