0

I have my own dictionary application WordYard and in that whenever we type in AutoCompleteTextView i am showing the words list in dropdown.

In addTextChangedListener of autoCompleteTextView i am querying for written text in sqlite database. Since database is very huge of 1.5 lac words it takes time to make the arraylist of particular text.

Suppose I wrote 'A' then this string will searched in database and written inside arraylist of limit 15 data starting from 'A'. On scrolling the dropdown list i am adding next 15 words in getView of adapter.

Scrolling is fine but whenever i type in autocompleteTextview to read 15 words from database also it take time if we write faster. Please tell me if there is any other method i can do it to make my app better.

sajal
  • 169
  • 10

1 Answers1

1

Everytime you type anything within AutoCompleteTextView a query to your relative huge database is sent thus causing the (justified) delay.

The addTextChangedListener (TextWatcher watcher); method needs a TextWatcher object to operate. What your are going to to is create a TextWatcher and override it's afterTextChanged (Editable s) method in order to perform queries to your database less often.You will also need a custom Filter for that.

autoCompleteTextView.addTextChangedListener(new TextWatcher() {
   public void onTextChanged(CharSequence s, int start, int before, int count) {
      yourAdapter.getFilter().filter(s);
   }

then you will create a class that extends [Filter][1] and override the methods suitable to your needs.

For example optimize your implementation to send queries only after 4 characters are typed or some time has passed.

George Daramouskas
  • 3,720
  • 3
  • 22
  • 51