5

I need to implement a search interface in my Android app that would filter several RecyclerView inside a ViewPager.

I have already implemented both EditText and SearchView widgets and try to see differences.

The listeners i am interrested in are :

   myEditText.addTextChangedListener(new TextWatcher() {

            public void afterTextChanged(Editable s) {}

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

            public void onTextChanged(CharSequence s, int start, int before, int count) {}
        });

And :

mySearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextChange(String newText) {

        textView.setText(newText);
        return true;
    }

    @Override
    public boolean onQueryTextSubmit(String query) {
        textView.setText(query);
        return true;
    }
  1. Am i missing some important features that SearchView would allow & that EditText does not ?

  2. With both of these widgets, Am i able to search among RecyclerView s inside ViewPager with a single "search-view" ?

I don't want an ACTION_SEARCH or any added dialog view for the search.

Thanks in advance !

Tom3652
  • 2,540
  • 3
  • 19
  • 45

1 Answers1

4

Main Difference between Edittext and SearchView is that you can use SearchView as direct implementation for Searching facility in listView/RecyclerView and on the other side if you use Edittext for this,you have to manually implement code for searching.

Let me provide you direct links for both of this scenarios :

This implementation is for SearchView :

  1. https://www.androidhive.info/2017/11/android-recyclerview-with-search-filter-functionality/

Second one is for EditText :

  1. https://stackoverflow.com/a/40757114/10752962

If you are using searchView,also look at this link :

  1. https://stackoverflow.com/a/34880830/10752962

This will use Edittext For Search data from RecyclerView with custom implementation.

Now, you have to decide which one is more suitable for you and yes,tell me if i can improve my answer or if my answer is unclarified..

Vivek Thummar
  • 395
  • 4
  • 17
  • Thanks for your answer, so if i understood correctly you are telling me that SearchView is a better tool than EditText if i am working with RecyclerViews ? If yes, could you improve your answer and tell me in which way please ? I am aware of the ```Filterable``` interface, but it has nothing to do with EditText or SearchView in my opinion.. Am i right ? – Tom3652 Jan 23 '20 at 16:35
  • 1
    Well,u have to implement "Filterable" in adapter class and it will create an @override method " getFilter()" and this is main thing to do..so,Filtarable interface is needed to use SearchView. – Vivek Thummar Jan 24 '20 at 06:48
  • And yes,other thing is if you use edittext for search filter,u have to use it's "afterTextChanged" method.but sometimes is makes device lag.So, i think u have to use SearchView, just add it to your app and try to understand and u got it. – Vivek Thummar Jan 24 '20 at 06:54