0

I'm trying to work with a MultiAutocompleteTextView in such way that whenever I type a character in the textview, an event will be fired OR after 2-3 elements have been typed, fire the event again.

The reason I work with multiautocomplete is because I also need the autocompletion feature .

Is there such an event that can be triggered after every character or 2-3 characters typed? Thanks!

funkycookie
  • 226
  • 2
  • 16
  • all you need is an `Adapter` set by `setAdapter()` method and its `Filterable` features, in order to avoid writing your own `Filter` from the scratch you can use `SimpleCursorAdapter` and `FilterQueryProvider` – pskink Oct 01 '14 at 10:01
  • cheers! could you show me code example in order to get a better insight? – funkycookie Oct 01 '14 at 10:03
  • see my answer here http://stackoverflow.com/questions/19858843/how-to-dynamically-add-suggestions-to-autocompletetextview-with-preserving-chara?answertab=oldest#tab-top on how i did it for AutoCompleteTextView, the similat adapter can be used for MultiAutoCompleteTextView – pskink Oct 01 '14 at 10:09
  • I found an easier solution. There's an event that can handle this: addTextChangedListener. But right now I'm trying to see whether I can fire my method only after 3 characters have been typed. – funkycookie Oct 01 '14 at 10:17
  • this is bad solution, see my comment below – pskink Oct 01 '14 at 10:32

1 Answers1

1

Yes you can use add a TextWatcher and TextChangedListener to your edit Text like this:

  myEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            //check count or count in edit text and do something
        }

        @Override
        public void afterTextChanged(Editable arg0) {
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }
    });

http://developer.android.com/reference/android/text/TextWatcher.html

AndroidEnthusiast
  • 6,557
  • 10
  • 42
  • 56
  • if you use a TextWatcher, then why to use MultiAutoCompleteTextView? if TextWatcher is good enough then use EditText with it, soon downvoting then... – pskink Oct 01 '14 at 10:28
  • @pskink because like I mentioned, I also need the autocomplete feature. I'm trying to get FB locations inside the text element. Such as I type 1 character, method will be called and will show all the locations starting with that character. I'm not really aware at the moment how to do that since whenever I call the method on the frontend, it will go to the backend and then call the facebook api for that method, but this takes around 2-3 seconds. So for each character I put, if it is to call the method, for 3-4 characters it will be too much time – funkycookie Oct 01 '14 at 10:33
  • then use an adapter as i said in my first comment – pskink Oct 01 '14 at 10:40
  • will try following the same approach :) but like I mentioned, in my case, this takes too much time for firing up the event after each character typed.d That's why I was considering firing it up after 2-3 characters have been typed, reason for considering using a textwatcher @pskink – funkycookie Oct 01 '14 at 10:48
  • call setThreshold(3) and use custom FilterQueryProvider, it will just work, no TextWatcher involved at all – pskink Oct 01 '14 at 10:52
  • is there a way I could contact you via Skype or mail? I have some more questions would like to ask :) – funkycookie Oct 01 '14 at 10:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62247/discussion-between-pop-alex-cristian-and-pskink). – funkycookie Oct 01 '14 at 10:58
  • @pskink - how should I handle the setContentView since I'm working with my ACTV by finding its ID? – funkycookie Oct 02 '14 at 09:05
  • what you mean? what id? – pskink Oct 02 '14 at 09:16