CaveMan
CaveMan

Reputation: 163

Android SearchView without Intent

It is little abstract question but i cannot find any solution for that. Is there any way for using searchview without intent ? I am trying to search something without creating activity again.

Upvotes: 4

Views: 295

Answers (2)

gustavogbc
gustavogbc

Reputation: 715

Actually you don't need use any of these if you want. You may simply override the callbacks of the SearchView.OnQueryTextListener.

See the following example:

public class MySearchActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        SearchView searchView = (SearchView) findViewById(R.id.searchView);

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String s) {
                //Every hit on "Enter"
                doSearch(s);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                //Any change in the query string
                doSearch(s);
                return true;
            }
        });     
    }

    /*
    * Implement your search into a SQLite database, webservice or anything else...
    * */
    private void doSearch(String query) {
        searchAndNotifyAdapterWithResult(query);
    }
}

Upvotes: 2

piotrek1543
piotrek1543

Reputation: 19351

Actually there are some libraries which you can use for this

  1. MaterialSearchView: https://github.com/MiguelCatalan/MaterialSearchView
  2. Android-Material-SearchView: https://github.com/EugeneHoran/Android-Material-SearchView
  3. MaterialDialogSearchView: https://github.com/TakeoffAndroid/MaterialDialogSearchView
  4. SerchView: https://github.com/lapism/SearchView

Of course, these are only examples of many others which you would find on GitHub page. So be patient and find the one which would be the most comfortable to you and the best fit for your app.

Upvotes: 2

Related Questions