Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Search Type Of android SearchView?

In Android SearchView widget that provides a UI. It will search query and submit a request to a search provider.

There are different type of search query Provided by Collections like BinarySearch...

What kind of Search query performed by Android Widget SearchView.?

(BinarySearch Or LinerSearch Or anything else...)

like image 591
Learning Always Avatar asked Sep 06 '17 11:09

Learning Always


3 Answers

If you ask about android.widget.SearchView, you can implement interface android.widget.SearchView.OnQueryTextListener and do anything you want inside it.

For example, let's create OnQueryTextListener as Activity part:

public class MyActivity implements OnQueryTextListener{

    @Override
    protected void onCreate(Bundle savedInstanceState){

        ...

        SearchView s=new SearchView(this);
        s.setFitsSystemWindows(true);
        s.setMaxWidth(Integer.MAX_VALUE);
        s.setIconifiedByDefault(false);
        s.setOnQueryTextListener(this);  // <--- this sets listener

        ...

    }

And now two methods what you have to implement:

    @Override
    public boolean onQueryTextChange(String newText){
        return false;  // <--- you can leave it empty!
    }

    @Override
    public boolean onQueryTextSubmit(String query){
        if(!query.isEmpty()){
            do_something_on_user_post();
        }
        return false;
    }
like image 87
bukkojot Avatar answered Oct 10 '22 06:10

bukkojot


It is up to the app developer to search the data and to provide the results to the search widget. The search widget provides a framework for the app to perform its searches but does not search the data directly. From Creating a Search Interface:

Searching your data

The process of storing and searching your data is unique to your application. You can store and search your data in many ways, but this guide does not show you how to store your data and search it. Storing and searching your data is something you should carefully consider in terms of your needs and your data format.

So you can search your data in the way that makes the most sense for how the data is stored and organized.

like image 38
Cheticamp Avatar answered Oct 10 '22 07:10

Cheticamp


An Android "Widget" is to perform the search but does not search the data directly you implement your own search algorithm

like image 4
alacoo Avatar answered Oct 10 '22 08:10

alacoo