musale
musale

Reputation: 584

Tagged Text in Android EditView

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

Upvotes: 0

Views: 77

Answers (3)

Joyal  C  Joseph
Joyal C Joseph

Reputation: 288

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.

Upvotes: 0

Shrenik Shah
Shrenik Shah

Reputation: 1990

Check out below library that serves what you want

Android chips with AutoComplete

Happy Coding! :)

Upvotes: 2

Hadi
Hadi

Reputation: 159

You can use these libraries:

AndroidTagView

EditTag

TagsEditText

Upvotes: 1

Related Questions