androidautocompletetextviewmultiautocompletetextviewtokenautocomplete

Android AutoCompleteTextView with '@' mentions filtering like twitter and facebook


I have a requirement for implementing an edit text that the user can type in a anything but when they type in a new word that starts with '@' the autocomplete should start showing potential users.

I understand how to use the AutoCompleteTextView function for filtering. But I am not sure how to go about capturing the characters from the last word after the '@' symbol (ignoring any previous words).

Consequently when the user has been selected from the AutoCompleteTextView list, it should replace the the word with '@', eg.


"This is a message for @steve"


when the user clicks on "Steve" from the list, the text should replace to:


"This is a message for Steve"


I also need to obtain the string in a form that I can send off to the server. i.e. from the above example I would need to send off the string:


"This is a message for [username:steve@bloggs.com, id:44]."


I have looked at https://github.com/splitwise/TokenAutoComplete

Which seems great for typing emails in a list, but I am not sure how to cater it for my needs. Bare in mind, I need to support multiple/duplicate mentions:

eg


"This is a message for Steve and Bob. this is the second sentence in the message for Bob"


If anyone knows or has done anything like this, would really appreciate it!


Solution

  • I ended up using the spyglass library from linkedin which does exactly what I was looking for. It provides a MentionsEditText (that can be customised). I also used a ListPopupWindow to show the suggestions in a list (like an AutoCompleteTextView).

    Here is the link...

    https://github.com/linkedin/Spyglass