Example usage for android.widget SearchView setOnQueryTextListener

List of usage examples for android.widget SearchView setOnQueryTextListener

Introduction

In this page you can find the example usage for android.widget SearchView setOnQueryTextListener.

Prototype

public void setOnQueryTextListener(OnQueryTextListener listener) 

Source Link

Document

Sets a listener for user actions within the SearchView.

Usage

From source file:com.anadoluuniversity.tinyreader.OcrCaptureActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    if (getSupportFragmentManager().findFragmentByTag("FragmentCamera") != null
            && getSupportFragmentManager().findFragmentByTag("FragmentCamera").isVisible()) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_search, menu);
        MenuItem item = menu.findItem(R.id.menuSearch);

        SearchView searchView = (SearchView) item.getActionView();

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override/*from w ww. j  a  v a2 s  .c o  m*/
            public boolean onQueryTextSubmit(String query) {
                Log.d("searchbar_submit", query);
                wordToSearch = query;
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.gnufabio.costituzione.SearchResultsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.actionbar_mainscreen, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setOnQueryTextListener(this);

    return true;/* w  w w  . ja  v a  2s .c o  m*/
}

From source file:com.mindprotectionkit.freephone.ui.ContactsListActivity.java

@SuppressLint({ "NewApi", "NewApi" })
private void initializeSearch(android.widget.SearchView searchView) {
    searchView.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() {
        @Override//  w  w  w.  j av a2  s. c  om
        public boolean onQueryTextSubmit(String query) {
            ContactsListActivity.this.queryFilter = query;
            ContactsListActivity.this.getLoaderManager().restartLoader(0, null, ContactsListActivity.this);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return onQueryTextSubmit(newText);
        }
    });
}

From source file:com.innoc.secureline.ui.ContactsListActivity.java

@SuppressLint("NewApi")
private void initializeSearch(android.widget.SearchView searchView) {
    searchView.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() {
        @Override/*from   ww w .j a v  a2s  . c om*/
        public boolean onQueryTextSubmit(String query) {
            ContactsListActivity.this.queryFilter = query;
            ContactsListActivity.this.getLoaderManager().restartLoader(0, null, ContactsListActivity.this);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return onQueryTextSubmit(newText);
        }
    });
}

From source file:org.que.activities.MainNavigationActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (menu != null) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.main, menu);

        final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            public boolean onQueryTextSubmit(String query) {
                Toast.makeText(MainNavigationActivity.this, "Submitted: " + query, Toast.LENGTH_LONG).show();
                searchView.onActionViewCollapsed(); //close search view
                startSearch(query);//  w w  w  .java 2s.c om
                return true;
            }

            public boolean onQueryTextChange(String arg0) {
                return true;
            }
        });
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.jpuyo.barcelonaplaces.app.ui.activity.main.PlacesListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.placeslist_fragment, container, false);

    mApp = (BarcelonaPlacesApp) getActivity().getApplicationContext();

    mPlacesAdapter = new PlacesCursorCardAdapter(getActivity(), this);
    mPlacesAdapter.setPlaceDetailManager(mApp.getPlacesDetailManager());

    CardListView mListView = (CardListView) rootView.findViewById(R.id.cardlistview_placeslist_fragment);
    mListView.setAdapter(mPlacesAdapter);

    SearchView mSearchView = (SearchView) rootView.findViewById(R.id.searchview_place);
    mSearchView.setFocusable(true);// w  w  w.j a  v  a2  s.c om
    mSearchView.setIconifiedByDefault(false);
    mSearchView.setOnQueryTextListener(this);

    return rootView;
}

From source file:net.ustyugov.jtalk.activity.XMLConsole.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.xml, menu);//from w w  w . j  a  v  a2 s .  c  o  m

    MenuItem.OnActionExpandListener listener = new MenuItem.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            searchString = "";
            updateList();
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }
    };

    SearchView searchView = new SearchView(this);
    searchView.setQueryHint(getString(android.R.string.search_go));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            searchString = query;
            updateList();
            return true;
        }
    });

    MenuItem item = menu.findItem(R.id.search);
    item.setActionView(searchView);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    item.setOnActionExpandListener(listener);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.openerp.addons.note.AddFollowerFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_fragment_note, menu);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_note_search).getActionView();
    searchView.setOnQueryTextListener(getQueryListener(listAdapters));

    searchView.setOnCloseListener(new OnCloseListener() {
        @Override/*from w w w. ja  va 2s .  c  o m*/
        public boolean onClose() {
            getPartnersFromLocal();
            return false;
        }
    });

    // disabling the COMPOSE NOTE,WRITE,CANCEL options
    MenuItem item_compose = menu.findItem(R.id.menu_note_compose);
    item_compose.setVisible(false);
    MenuItem item_write = menu.findItem(R.id.menu_note_write);
    item_write.setVisible(false);
    MenuItem item_cancel = menu.findItem(R.id.menu_note_cancel);
    item_cancel.setVisible(false);
}

From source file:com.lithiumli.fiction.LibraryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.library, menu);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from   w  ww.  j  a va 2 s  .  co  m
        public boolean onQueryTextChange(String query) {
            // TODO XXX causes NPE on orientation change
            // FictionListFragment f = mTabsAdapter.getFragment(mViewPager.getCurrentItem());
            // f.filter(query);
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }
    });

    return super.onCreateOptionsMenu(menu);
}

From source file:com.jwork.dhammapada.ChapterFragment.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from w  w  w  .j a  v a  2  s  .  c om*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    log.d(this, "onCreateView()");

    view = inflater.inflate(R.layout.chapter_list, container, false);
    if (view == null) {
        log.w(this, "Problem inflating view, returned null");
        return null;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        final android.widget.SearchView svSearch = (android.widget.SearchView) view
                .findViewById(R.id.sv_search);
        svSearch.setOnQueryTextListener(new android.widget.SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                InputMethodManager imm = (InputMethodManager) getActivity()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(svSearch.getWindowToken(), 0);
                search(query);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
    } else {
        ImageButton btnSearch = (ImageButton) view.findViewById(R.id.button_search);
        btnSearch.setOnClickListener(this);
        //           txtSearch = (EditText)view.findViewById(R.id.text_search);
        //           txtSearch.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        //              @Override
        //              public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        //                 if (actionId == EditorInfo.IME_ACTION_SEARCH) {
        //                    search(v.getText());
        //                    return true;
        //                 }
        //                 return false;
        //              }
        //           });
    }
    return view;
}