Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature request] Search on typing #11

Closed
letientai299 opened this issue Sep 13, 2016 · 4 comments
Closed

[Feature request] Search on typing #11

letientai299 opened this issue Sep 13, 2016 · 4 comments

Comments

@letientai299
Copy link

For now, the search action can only be trigger manually. I'd like trigger the search after some delay during typing. Unfortunately, with current implementation, I cannot call the listener from my subclass.

@nserguier
Copy link

Hi lentientai,

I wanted to achieve the same thing as you and I found a solution using a TextWatcher.
First, you create your TextWatcher that will execute your code to update the search when the text changes in the EditText:

TextWatcher searchWatcher = new TextWatcher() {

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

        @Override
        public void onTextChanged(final CharSequence s, int start, int before, int count) {
            updateSearch(s);
        }

        @Override
        public void afterTextChanged(Editable s) {
        }
    };

Then, you get the EditText component from the MaterialSearchBar and you attach your TextWatcher to it:

EditText searchEdit = (EditText) mSearchBar.findViewById(com.mancj.materialsearchbar.R.id.mt_editText);
searchEdit.addTextChangedListener(searchWatcher);

And that's all! I hope this will solve your problem and help other people achieve this.

@letientai299
Copy link
Author

Thank @nserguier.

Actually that what I have done. But it requires knowledge about internal implementation of the library (in this case, the ID of EditText). While that solution works, I still think that it would be better if the library itself offer such feature.

@mancj mancj closed this as completed Oct 8, 2016
@letientai299
Copy link
Author

@mancj May I know the reason for closing this?

@mancj
Copy link
Owner

mancj commented Oct 9, 2016

Thought@nserguier answered your question. This is not possible in the current release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants