onClick in edittext that cannot be editable

Asked

Viewed 620 times

1

How to make an event click on an edittext, enabled="false" ? (I couldn’t do it without the focus being on edittext, enabled="true")

Or, an event click on an edittext that cannot be editable.

Code below:

....

        <android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxLength="20"
            android:textColorHint="#FFF8E1"
            android:theme="@style/StyledTilEditText"
            android:clickable="true"
            android:id="@+id/pass_conta">

            <EditText
                android:id="@+id/edt_Password_conta"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="10dp"
                android:fontFamily="sans-serif-condensed"
                android:hint="@string/senha_hint_string"
                android:inputType="textPassword"
                android:maxLength="20"
                android:maxLines="1"
                android:text="123456"
                android:singleLine="true"
                android:textColor="#D3D3D3"
                android:textSize="15dp"
                android:clickable="true"
                android:enabled="false"/>

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

Code on the Activity:

.....
        mSenha.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getContext());
                dialogBuilder.setTitle("Deseja alterar a senha?")
                        .setMessage("Para alterar a senha é necessário fazer logoff e entrar em \"\"Esqueci a Senha\"\"")
                        .setCancelable(true)
                        .setPositiveButton("Sim", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                SaveSharedPreferences.clearLoginPreferences(getContext());
                                intent = new Intent(AlterarContaActivity.this,NewLoginActivity.class);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                                startActivity(intent);
                                Toast("Digite o email e vá em esqueci a senha");
                            }
                        }).setNegativeButton("Não", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).show();
            }
        });

......

2 answers

1


Try:

android:focusable="false"
android:enabled="true"

1

Do you want Edittext to receive focus without being editable? If so, just call

editText.setKeyListener(null);

If you want it to be editable again, before setting the System to null, get and store the original System with

editText.getKeyListener();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.