Android SearchView.onQueryTextSubmit (String request)

I'm having trouble sending my submit button for the request to work. I have this part of my code here.

searchView.setIconifiedByDefault(true); //iconify the widget
    searchView.setSubmitButtonEnabled(true);

and I also have a listener

new SearchView.OnQueryTextListener(){
  @Override
    public boolean onQueryTextChange(String newText) {
    // TODO Auto-generated method stub
        return false;
    }


        @Override
        public boolean onQueryTextSubmit(String query) {
            // TODO Auto-generated method stub
                            //Output the new list with the query results

            Context context = getApplicationContext();
            CharSequence start = "Start";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, start, duration);
            toast.show();
            return false;
        }
    };

When the submit button is pressed, it does not show a toast, so I assume that when you click the submit button, it does not do what it should do. I do not know what is wrong here.

+4
source share
4 answers

You need to call

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener());

in your searchview.

+6
source

For other ppls if they need or are looking for help

mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener(){

           @Override
           public boolean onQueryTextSubmit(String s) {
               Toast.makeText(context,"Our word : "+s,Toast.LENGTH_SHORT).show();
               return false;
           }

           @Override
           public boolean onQueryTextChange(String s) {
               return false;
           }
       });
       return true;
    }
+3
source

SearchView.OnQueryTextListener?

, onCreateOptions MainActivity.

My onCreateOptions:

public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater menuInflator = getMenuInflater();
    menuInflator.inflate(R.menu.main, menu);

    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    searchView.setOnQueryTextListener(this);

    return super.onCreateOptionsMenu(menu);

My onQuerySubmit:

public boolean onQueryTextSubmit(String query) {
    Toast.makeText(getApplicationContext(), "MY NIGGA WE MADE IT", Toast.LENGTH_LONG).show();

    return false;
}

, goodluck!

0
source

You return falseat the end when, in accordance with the documentation, you must return true:

The listener can override the standard behavior by returning true to indicate that it has processed the send request. Otherwise, return false to allow SearchView to process the view, triggering any associated intent.

0
source

All Articles