tiper / MaterialSpinner

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

Spinner Items Not Closing #22

Closed githeyj closed 4 years ago

githeyj commented 4 years ago

I have noticed that the spinner items does not close on some devices even after successfully selecting the item of choice

dehghanimehrdad commented 4 years ago

same problem on lg g4 running android 6

dehghanimehrdad commented 4 years ago

solved it using : materialSpinnerProvince.setOnItemSelectedListener(new MaterialSpinner.OnItemSelectedListener() { @Override public void onItemSelected(MaterialSpinner materialSpinner, View view, int i, long l) { materialSpinner.clearFocus(); }

        @Override
        public void onNothingSelected(MaterialSpinner materialSpinner) {

        }
    });
githeyj commented 4 years ago

@dehghanimehrdad materialSpinner.clearFocus(); did not solve the issue.

tiper commented 4 years ago

Hi @dehghanimehrdad and @githeyj please take a look here and let me know if it helped.

githeyj commented 4 years ago

@tiper , I tried the solution but it did not work. Please note that when you have one or two spinners, it works fine; but when the spinners are several especially on a scroll view, some spinners misbehave by not closing items......thats my experience on low-end devices

tiper commented 4 years ago

@githeyj Can you provide a sample using the latest version of this component so I can debug the issue?

githeyj commented 4 years ago

@tiper below is the sample code...

<com.tiper.MaterialSpinner android:id="@+id/spinner_gender" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginBottom="7dp" android:descendantFocusability="beforeDescendants" android:focusable="true" android:focusableInTouchMode="true" android:hint="Select Gender" android:windowSoftInputMode="stateAlwaysHidden" app:spinnerMode="bottomsheet" />

                        <com.tiper.MaterialSpinner
                            android:id="@+id/spinner_nannytype"
                            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginBottom="7dp"
                            android:descendantFocusability="beforeDescendants"
                            android:focusable="true"
                            android:focusableInTouchMode="true"
                            android:hint="Select Nanny Type"
                            android:singleLine="true"
                            app:spinnerMode="bottomsheet" />

                        <com.tiper.MaterialSpinner
                            android:id="@+id/spinner_paytype"
                            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginBottom="7dp"
                            android:descendantFocusability="beforeDescendants"
                            android:focusable="true"
                            android:focusableInTouchMode="true"
                            android:hint="Select Pay Type"
                            android:singleLine="true"
                            android:windowSoftInputMode="stateAlwaysHidden"
                            app:spinnerMode="bottomsheet" />

                        <com.tiper.MaterialSpinner
                            android:id="@+id/spinner_payrange"
                            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginBottom="7dp"
                            android:descendantFocusability="beforeDescendants"
                            android:focusable="true"
                            android:focusableInTouchMode="true"
                            android:hint="Select Pay Range"
                            android:singleLine="true"
                            android:windowSoftInputMode="stateAlwaysHidden"
                            app:spinnerMode="bottomsheet" />

                        <com.tiper.MaterialSpinner
                            android:id="@+id/spinner_endorsement"
                            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginBottom="7dp"
                            android:descendantFocusability="beforeDescendants"
                            android:focusable="true"
                            android:focusableInTouchMode="true"
                            android:hint="Select Endorsement"
                            android:singleLine="true"
                            android:windowSoftInputMode="stateAlwaysHidden"
                            app:spinnerMode="bottomsheet" />

                        <com.tiper.MaterialSpinner
                            android:id="@+id/spinner_skill"
                            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginBottom="7dp"
                            android:descendantFocusability="beforeDescendants"
                            android:focusable="true"
                            android:focusableInTouchMode="true"
                            android:hint="Select Experience"
                            android:singleLine="true"
                            android:windowSoftInputMode="stateAlwaysHidden"
                            app:spinnerMode="bottomsheet" />

                        <com.tiper.MaterialSpinner
                            android:id="@+id/spinner_levelOfEducation"
                            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginBottom="7dp"
                            android:descendantFocusability="beforeDescendants"
                            android:focusable="true"
                            android:focusableInTouchMode="true"
                            android:hint="Select Level of Education"
                            android:singleLine="true"
                            android:windowSoftInputMode="stateAlwaysHidden"
                            app:spinnerMode="bottomsheet" />

                        <com.tiper.MaterialSpinner
                            android:id="@+id/spinner_religion"
                            style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:layout_marginBottom="7dp"
                            android:descendantFocusability="beforeDescendants"
                            android:focusable="true"
                            android:focusableInTouchMode="true"
                            android:hint="Select Your Religion"
                            android:singleLine="true"
                            android:windowSoftInputMode="stateAlwaysHidden"
                            app:spinnerMode="bottomsheet" />
githeyj commented 4 years ago

The Spinners are aligned as below

githeyj commented 4 years ago

Hi @tiper did you find anything?

tiper commented 4 years ago

Hi @githeyj you need to add android:descendantFocusability="beforeDescendants", android:focusable="true" and android:focusableInTouchMode="true" to the parent of the spinner, not on the spinner itself.

Example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="beforeDescendants"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

    <com.tiper.MaterialSpinner
        android:id="@+id/spinner_levelOfEducation"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="7dp"
        android:hint="Select Level of Education"
        android:singleLine="true"
        android:windowSoftInputMode="stateAlwaysHidden"
        app:spinnerMode="bottomsheet" />

    <com.tiper.MaterialSpinner
        android:id="@+id/spinner_religion"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="7dp"
        android:hint="Select Your Religion"
        android:singleLine="true"
        android:windowSoftInputMode="stateAlwaysHidden"
        app:spinnerMode="bottomsheet" />

</LinearLayout>

Can you please try that and give me back feedback?

manivannan23111996 commented 4 years ago

same issue

Hi @githeyj you need to add android:descendantFocusability="beforeDescendants", android:focusable="true" and android:focusableInTouchMode="true" to the parent of the spinner, not on the spinner itself.

Example:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:descendantFocusability="beforeDescendants"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical">

    <com.tiper.MaterialSpinner
        android:id="@+id/spinner_levelOfEducation"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="7dp"
        android:hint="Select Level of Education"
        android:singleLine="true"
        android:windowSoftInputMode="stateAlwaysHidden"
        app:spinnerMode="bottomsheet" />

    <com.tiper.MaterialSpinner
        android:id="@+id/spinner_religion"
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="7dp"
        android:hint="Select Your Religion"
        android:singleLine="true"
        android:windowSoftInputMode="stateAlwaysHidden"
        app:spinnerMode="bottomsheet" />

</LinearLayout>

Can you please try that and give me back feedback?

It didn't work, when I put it in the immediate parent of the spinner. But works after putting android:focusable="true", android:descendantFocusability="beforeDescendants", android:focusableInTouchMode="true" in the root parent as mentioned.

Thanks @tiper

tiper commented 4 years ago

Hi @manivannan23111996 glad to read it.

I will try to update the readme file about this since it seems to be a general question.

@githeyj any update on your side?

githeyj commented 4 years ago

@tiper it worked after adding

android:focusable="true", 
android:descendantFocusability="beforeDescendants", 
android:focusableInTouchMode="true" 

on the root parent. Many thanks @tiper .