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

前端 未结 2 1099
予麋鹿
予麋鹿 2021-01-15 05:38

I got it working with custom \'@\' tokenizer. But it fails for the first autocompletion. My code works as a comma tokenizer where I get suggestion for any character and next

相关标签:
2条回答
  • 2021-01-15 06:12

    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_-]+)"

    0 讨论(0)
  • 2021-01-15 06:28

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

    0 讨论(0)
提交回复
热议问题