Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make part of text in EditText non-removable? #37

Closed
JoeRakhimov opened this issue Sep 11, 2017 · 1 comment
Closed

How to make part of text in EditText non-removable? #37

JoeRakhimov opened this issue Sep 11, 2017 · 1 comment

Comments

@JoeRakhimov
Copy link

I have an EditText which has default value '998'

    <EditText
        android:id="@+id/login"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="phone"
        android:text="998"/>

I am trying to make '998' non-removable:

public class MainActivity extends AppCompatActivity {

    static String INPUT_MASK_PHONE = "{998} [00] [000]-[00]-[00]";

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

        EditText login = (EditText) findViewById(R.id.login);

        MaskedTextChangedListener maskedTextChangedListener = new MaskedTextChangedListener(
                INPUT_MASK_PHONE,
                true,
                login,
                null,
                new MaskedTextChangedListener.ValueListener() {
                    @Override
                    public void onTextChanged(boolean b, @NotNull String s) {

                    }
                }
        );

        login.addTextChangedListener(maskedTextChangedListener);
        login.setSelection(login.length());

    }

}

I put 998 into {}, but this value can be removed when clear button is clicked. How to make '998' value non removable?

@taflanidi
Copy link
Collaborator

taflanidi commented Sep 20, 2017

Hey, @GayratRakhimov
Thanks for your question. Please accept my apology for the delayed reply.

I think you've misunderstood the concept of the "fixed" symbols a little bit.

Our library doesn't override Android keyboard behavior nor the SDK text field class behavior. Thus, if the user hits a Backspace button — the library allows him to do so. The modified string is re-formatted afterwards, and some of the erased characters may return back if there are any valuable symbols standing after, but essentially it's not prohibited to remove all the text from the field.

You may find more info in the corresponding thread for the iOS version. There, we had had a feature request to add non-removable symbols, which was rejected because of UX reasons and design ambiguity.

P.s. Should you have any questions, please do not hesitate to ask them and/or to close this issue if your problem is solved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants