1

I am trying to implement HashTag and mention by using AutocompleteTextview. It is working fine.

Depends on the entered keyword I am setting adapter in AutocompleteTextview. For that, I am using TextWatcher. It is showing the result. Till this working fine. But when I am typing the suggestion list is overlapping.

In the image, black Shadow is because of multiple pages. The number of pages is increasing when text in AutocompleteTextview is changing.

   autoCompleteTextview.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.toString().startsWith("@")) {
                   setupTagUserAutocomplete(data);
               } 
            else if (s.toString().startsWith("#")) {
                setupHashAutocomplete(list);
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

How to avoid this?

enter image description here

1 Answers1

0

You do not have to use TextWatcher. Using TextWatcher will create a new suggestion list every time the text is changed. You have to use an adapter for that purpose. That is the reason it is creating so many suggestion-lists.

You have to create a custom adapter since there is a custom requirement because of the two conditions ( @ and #).

Here is a link to an AutoCompleteTextView tutorial for you to go through. I hope you find this one useful.

https://www.studytonight.com/android/autocomplete-textview

In the above tutorial refer to the steps, but instead of an ArrayAdapter create a custom one. Inside that adapter, you can have that list according to the text.

Simran Sharma
  • 852
  • 7
  • 16
  • Thank you. Your suggestion is correct but in my case, I need to use `textWatcher` compulsory. Because according to the entered first character(ex. "@" or "#") I need to show suggestion. – Shyamaly Lakhadive Jan 18 '21 at 16:14
  • Got it. So you can check for the "#" using the `TextWatcher` but then for the rest of the text use the adapter. I mean if it is possible. That is what I am thinking. – Simran Sharma Jan 18 '21 at 16:23