Tagged Text in Android EditView

77 Views Asked by At

I would like to achieve an edit view that tags the text after a user has entered some text (in my case a phonenumber) and the user presses a comma. So for input that has Trevor Hansen, Alex Nelson, ... the output will be like this:

Courtesy: Google Material: Color Schemes

3

There are 3 best solutions below

0
Hadi On

You can use these libraries:

AndroidTagView

EditTag

TagsEditText

3
Shrenik Shah On

Check out below library that serves what you want

Android chips with AutoComplete

Happy Coding! :)

0
Joyal  C  Joseph On

Go through the below code, add a TextWatcher and your logic:

phoneNumber = (EditText) findViewById(R.id.phone);
tag = (TextView) findViewById(R.id.tag);

phoneNumber.addTextChangedListener(new TextWatcher() {

    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

    }

    @Override
    public void afterTextChanged(Editable editable) {

        String mobNo = editable.toString();

        if (mobNo != null && mobNo.length() >= 1) {

            if (mobNo.contains(",")) {
                mob = new SpannableString(mobNo.replace(",", ""));
                tag.setText(mob);
                phoneNumber.setText("");
            }
        }
    }
});

Add your logic for multiple data persistence.