1

I'm having android.support.v7.widget.AppCompatEditText inside TextInputLayout in my activity and added setOnFocusChangeListener for the editText. When ever the activity is opened its automatically called onFocusChange for the top first editText till android version 8. But when i was running it in android 9 and above onFocusChange for the top first editText is not getting called. Can you please suggest an idea to fix it.

Below is my activity,

public class MainActivity extends AppCompatActivity {

    private EIScanEditTextView edtUserName, passwordEdt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        passwordEdt = (EIScanEditTextView) findViewById(R.id.edt_password);
        edtUserName = (EIScanEditTextView) findViewById(R.id.edt_user_name);
        edtUserName.setTransformationMethod(new AllCapTransformationMethod());
        passwordEdt.setTransformationMethod(new AllCapTransformationMethod());
        edtUserName.setOnFocusChangeListener(new GenericTextWatcher(edtUserName));
        passwordEdt.setOnFocusChangeListener(new GenericTextWatcher(passwordEdt));
    }

    private class GenericTextWatcher implements View.OnFocusChangeListener {

        private final View view;

        private GenericTextWatcher(View view) {
            this.view = view;
        }

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            switch (view.getId()) {
                case R.id.edt_user_name:
                    String mCurrentFocus;
                    if (hasFocus) {
                        mCurrentFocus = Constants.InputFilePattern.KEY_OH;
                    }
                    break;
                case R.id.edt_password:
                    if (hasFocus) {
                        mCurrentFocus = Constants.InputFilePattern.KEY_PO;
                    }
                    break;
                default:
                    break;
            }
        }
    }

}

And my layout,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:padding="@dimen/control_padding_m"
    android:orientation="vertical"
    tools:context="com.example.eiscanning.login.MainActivity">

    <com.example.eiscanning.ui.ValidatedTextInputLayout
        android:id="@+id/user_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/control_padding_xs">

        <com.example.eiscanning.ui.EIScanEditTextView
            android:id="@+id/edt_user_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/username"
            android:inputType="text"
            app:fontName="Roboto-Regular.ttf" />

    </com.example.eiscanning.ui.ValidatedTextInputLayout >

    <com.example.eiscanning.ui.ValidatedTextInputLayout
        android:id="@+id/password"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="@dimen/control_padding_xs"
        app:passwordToggleEnabled="true">

        <com.example.eiscanning.ui.EIScanEditTextView
            android:id="@+id/edt_password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/password"
            android:imeOptions="actionGo"
            android:inputType="textPassword"
            app:fontName="Roboto-Regular.ttf" />

    </com.example.eiscanning.ui.ValidatedTextInputLayout>

</LinearLayout>

And i'm using below dependencies,

implementation 'com.android.support:appcompat-v7:25.3.1'
implementation 'com.android.support:support-v4:25.3.1'
implementation 'com.android.support:design:25.3.1'

Manifest.xml

<activity
            android:name=".login.MainActivity"
            android:exported="false"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"/>
James Z
  • 12,209
  • 10
  • 24
  • 44

0 Answers0