Search code examples
javaandroidtokenizewhatsappmultiautocompletetextview

Android MultiAutoCompleteTextView with custom tokenizer like as whatsapp GroupChat


I want to create custom tokenizer for @ like as whatspp feature (when open group and write @ then open popup for list and user can select any. Also user can remove that string of @.

I have found twitter like search feature (example), but in this, when user can write @ then do not show popup window of list. User can write something after @ then based on typing, popup window will show search result.

I want to show something like this:

enter image description here


Solution

  • I got solution for my question.

    i have create own custom view for multiautocompletetextview and add performFiltering method for open popup after @sign.

    public class KcsMultiAutoCompleteTextView extends MultiAutoCompleteTextView {
        public KcsMultiAutoCompleteTextView(Context context) {
            super(context);
        }
    
        public KcsMultiAutoCompleteTextView(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
    
        public KcsMultiAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
    
        @Override
        protected void performFiltering(CharSequence text, int start, int end, int keyCode) {
            if (text.charAt(start) == '@') {
                start = start + 1;
            } else {
                text = text.subSequence(0, start);
                for (int i = start; i < end; i++) {
                    text = text + "*";
                }
            }
            super.performFiltering(text, start, end, keyCode);
        }
    
    }