Multiautocompletetextview, Show autocomplete drop down only when user presses a key after '@' key (like mention in FB app)

僤鯓⒐⒋嵵緔 提交于 2019-12-01 11:37:08

If you want to do mention query with the character '@', you can do query onTextChanged as below:

        @Override
        public void onTextChanged(CharSequence s, int start, int before, final int count) {
            if (s.length() > 0) {
                // Todo: query mentions
                Matcher mentionMatcher = Pattern.compile("@([A-Za-z0-9_-]+)").matcher(s.toString());
                // while matching
                while (mentionMatcher.find()) {
                   yourSearchText = s.toString().substring(mentionMatcher.start() + 1, mentionMatcher.end());
                  // do query with yourSearchText below
                }
           }
       }

Note: you also can do hashTag query with the character '#' by replace it in

"@([A-Za-z0-9_-]+)"

https://github.com/linkedin/Spyglass check this out , having all the use cases for mentions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!