0

I am doing a dictionary app based on this project. This is my AutoCompleteTextView:

searchAutoCompleteTextView.setThreshold(1);
        searchAutoCompleteTextView.setAdapter(new WordAutoComplite(ZhuangDictActivity.this, null));
        searchAutoCompleteTextView.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) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.length() > 0) {
                    char key = GB2Alpha.Char2Alpha(s.charAt(0));
                    if (currentChar != key) {
                        currentChar = key;
                        tableName = DatabaseHelper.transTableName(key);
                    }
                }
            }
        });

My CursorAdapter:

@Override
    public Cursor runQueryOnBackgroundThread(CharSequence word) {
        return databaseHelper.queryAutoComplete(tableName, word.toString(), DEFAULT_AUTOCOMPLETE_LIMIT);
    }

    /* (non-Javadoc)
     * @see android.widget.CursorAdapter#convertToString(android.database.Cursor)
     */
    @Override
    public CharSequence convertToString(Cursor cursor) {
        return cursor.getString(0);
    }

The DatabaseHelper.java is available here and here is the complete code of my activity.

I noticed a bug. Let say I search "apple" and I exit the app. Then I reenter the app and search "apple" again, this time the result cannot be found. In order to solve this problem, I have to type another alphabet randomly other than "a". If after I exit the app and return to it, I search "book" before searching "apple", I will be able to get the result. Seem like the app lost connection to the database. How should I solve this problem?

user2872856
  • 2,003
  • 2
  • 21
  • 54
  • see ny comment i wrote 50 minutes ago here http://stackoverflow.com/questions/24096851/arrayadapter-need-to-be-clear-even-i-am-creating-a-new-one – pskink Jun 07 '14 at 13:09
  • You are saying that I should clear the adapter on postexecute? – user2872856 Jun 07 '14 at 13:40
  • ok now i see that you are using a Filter behind the scene, so what is a TextWatcher for? – pskink Jun 07 '14 at 13:45
  • To show the drop down autocomplete searching suggestion as we type. – user2872856 Jun 07 '14 at 14:00
  • 1
    you dont need it, see my answer here http://stackoverflow.com/questions/19858843/how-to-dynamically-add-suggestions-to-autocompletetextview-with-preserving-chara, in your case you dont need a FilterQueryProvider, you can do the same in runQueryOnBackgroundThread – pskink Jun 07 '14 at 14:04
  • I would appreciate if you could provide me an answer. Thank you. – user2872856 Jun 07 '14 at 14:44

0 Answers0