Reputation: 584
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:
Upvotes: 0
Views: 77
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
Reputation: 1990
Check out below library that serves what you want
Android chips with AutoComplete
Happy Coding! :)
Upvotes: 2