K
K
kirawa2014-03-27 10:36:48
Android
kirawa, 2014-03-27 10:36:48

How to work with search in android?

There is a code

public void onTextWatcher(final CustomAdapter customAdapter){
        this.customAdapter = customAdapter;
        textWatcher =  new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3){
            }
            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
                customAdapter.getFilter().filter(editTextSearch.getText().toString());
                if (CustomAdapter.subItems.size() == 0){
                    Toast.makeText(context,"нет совпадений",Toast.LENGTH_SHORT).show();
                }
            }
            @Override
            public void afterTextChanged(Editable editable) {
            }
        };
        editTextSearch.addTextChangedListener(textWatcher);
    }

I want that when searching, if there are no matches, then something would be displayed. Now outputs with a delay of 1 character. Help to understand, please.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bimeg, 2014-03-27
@bimeg

customAdapter.getFilter().filter()
this is done in a separate thread and the result will come later. Therefore
uses the previous result.
If you have a custom filter, then the condition must be checked in publishResults

K
kirawa, 2014-03-27
@kirawa

Well tell me how to do what to use AsyncTask? At least point me

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question