I want to refer to this question , on how to implement the mention feature, but for android.
I want to know how it goes in the database specifically .
I want to refer to this question , on how to implement the mention feature, but for android.
I want to know how it goes in the database specifically .
I guess the answer was already provided the old post,
Listen to the input. When the user types an @, followed by a character, make a call to an url on your server (/user/lookup/?username=joe for example) that routes to a view which looks up up users beginning with joe. Return it as json and display it in a dropdown.
To make is much simpler, you need to use @
as a keyword that is going to be used for understanding the beginning of a user name .
e.g. user types the following message
... was with @nour at NYC
in Java you can detect the @
using regular expression,
boolean foundMatch = false;
Pattern regex = Pattern.compile("\\b(?:@)\\b");
Matcher regexMatcher = regex.matcher(subjectString);
foundMatch = regexMatcher.find();
This will match if the input string has a @
keyword
Now once you get the @
keyword take all character after @
till you get a white space. In this example nour
should be the result since its starts after @
and ends before a white space
.
In the server part you can the the recognized name as a USER_NAME
,
SELECT * FROM USERS WHERE USER_NAME = "nour";
Of-course the username needs to the unique.
Hope it helps.
It's mainly done by AutoCompleteTextView and handling the key events. I can't write such a code. I can give you simple main ideas. You listen to the user clicks on the keyboard by overrinding onKeyUp()
method
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_AT:
// @ is clicked
// get the usernames
return true;
default:
return super.onKeyUp(keyCode, event);
}
}
now you should start getting usernames from the database, put them inside the AutoCompleteTextView adapter to be filtered according to the user entries and when the user selects a friend or someone to be mentioned "or many" you add them to an ArrayList and push a notification to them.