Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead

Always getting this warning TextInputLayout: EditText added is not a TextInputEditText. Please switch to using that class instead. and not finishing Activity for First time. On Second time not getting an warning and activity finishing perfectly.

activity_login.xml

<LinearLayout
        android:id="@+id/ll_login_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center_horizontal"
        android:orientation="vertical"
        android:paddingBottom="@dimen/activity_vertical_margin"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:visibility="visible">


        <android.support.design.widget.TextInputLayout
            android:id="@+id/email_field"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="16dp"
            android:hint="@string/email_phone"
            android:paddingTop="48dp">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/et_email"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:inputType="textEmailAddress"
                android:paddingEnd="0dp"
                android:paddingStart="8dp" />

        </android.support.design.widget.TextInputLayout>

        <android.support.design.widget.TextInputLayout
            android:id="@+id/password_field"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/password"
            android:paddingBottom="16dp">

            <android.support.v7.widget.AppCompatEditText
                android:id="@+id/et_password"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:inputType="textPassword"
                android:paddingEnd="0dp"
                android:paddingStart="8dp" />

        </android.support.design.widget.TextInputLayout>


        <Button
            android:id="@+id/btn_login"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/button_login_social_margin"
            android:layout_marginStart="@dimen/button_login_social_margin"
            android:layout_marginBottom="@dimen/activity_vertical_margin"
            android:text="@string/login"
            android:textColor="@android:color/black" />

    </LinearLayout>

LoginActivity.java

    public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        final AppCompatEditText etEmailOrPh = (AppCompatEditText) findViewById(R.id.et_email);
        final AppCompatEditText etPassword = (AppCompatEditText) findViewById(R.id.et_password);
        final Button btnLogin = (Button) findViewById(R.id.btn_login);

        assert etEmailOrPh != null;
        assert etPassword != null;
        assert  btnLogin != null;

        btnLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String emailOrPhone = etEmailOrPh.getText().toString().trim();
                String password = etPassword.getText().toString().trim();

                if(emailOrPhone.isEmpty()){
                    etEmailOrPh.setError(getResources().getString(R.string.email_phone_mandatory));
                    etEmailOrPh.requestFocus();
                } else if(emailOrPhone.contains("@") && CommonUtil.isValidEmail(emailOrPhone)) {
                    etEmailOrPh.setError(getResources().getString(R.string.email_error));
                    etEmailOrPh.requestFocus();
                } else if(password.isEmpty()) {
                    etPassword.setError(getResources().getString(R.string.password_mandatory));
                    etPassword.requestFocus();
                } else {
                    SharedPreferences cache = LoginActivity.this.getSharedPreferences(Constants.SHARED_PREF_NAME, Context.MODE_PRIVATE);
                    final SharedPreferences.Editor preferenceEditor = cache.edit();
                    preferenceEditor.putInt(Constants.SHARED_PREF_ITEM_USER_ID, 1);
                    preferenceEditor.apply();
                    setResult(RESULT_OK);
                    finish();
                }
            }
        });

    }
}

Login Screen

like image 238
Naveen Kumar M Avatar asked Sep 23 '16 08:09

Naveen Kumar M


2 Answers

Change this EditText

android.support.v7.widget.AppCompatEditText

to this

android.support.design.widget.TextInputEditText

Full Code :

<android.support.design.widget.TextInputLayout
       android:id="@+id/email_field"
       android:layout_width="match_parent"
       android:layout_height="wrap_content"
       android:paddingBottom="16dp"
       android:hint="@string/email_phone"
       android:paddingTop="48dp">

    <android.support.design.widget.TextInputEditText
            android:id="@+id/et_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:inputType="textEmailAddress"
            android:paddingEnd="0dp"
            android:paddingStart="8dp"
        />
</android.support.design.widget.TextInputLayout>
like image 138
Harshad Pansuriya Avatar answered Sep 20 '22 19:09

Harshad Pansuriya


Try not using

<android.support.v7.widget.AppCompatEditText

instead use

<EditText

So you will get:

<EditText
            android:id="@+id/et_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:inputType="textEmailAddress"
            android:paddingEnd="0dp"
            android:paddingStart="8dp" />

After doing a bit of research on the issue i found this post:

EditText added is not a TextInputEditText. Please switch to using that class instead

let me know if it helps you.

like image 39
Just_someone Avatar answered Sep 20 '22 19:09

Just_someone