Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android SearchView.onQueryTextSubmit(String query)

I am having issues getting my submit button for the query 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 clicked, it does not show the toast so I am assuming that when the submit button is clicked, it is not doing what it is supposed to do. I don't know what is wrong here.

like image 934
user2159166 Avatar asked Nov 20 '13 06:11

user2159166


1 Answers

You have to call

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

on your SearchView.

like image 121
CommonSense Avatar answered Sep 30 '22 15:09

CommonSense