Example usage for android.widget SearchView.OnQueryTextListener SearchView.OnQueryTextListener

List of usage examples for android.widget SearchView.OnQueryTextListener SearchView.OnQueryTextListener

Introduction

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

Prototype

SearchView.OnQueryTextListener

Source Link

Usage

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  ww.  ja  va 2  s.  c om*/

    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: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);//from w  w w. j a  va 2s .  c  om
                return true;
            }

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

From source file:eu.nubomedia.nubomedia_kurento_health_communicator_android.kc_and_client.ui.activity.ItemListActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    AppUtils.setDefaults(ConstantKeys.FROMLOGIN, "false", this);

    int itemId = item.getItemId();
    if (itemId == R.id.add_group) {
        if (Preferences.isGroupAutoRegister(this)) {
            showPopup();/*from  www .  j  a  v a2  s  . c  om*/
        } else {
            Toast.makeText(this, getString(R.string.create_group_access_deny), Toast.LENGTH_SHORT).show();
        }
    } else if (itemId == R.id.sync_contacts) {
        sendContactsRequest();
    } else if (itemId == R.id.search) {
        SearchView searchView = (SearchView) mMenu.findItem(R.id.search).getActionView();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String s) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                if (mViewPager.getCurrentItem() == 0) {
                    groupsAdapter.getFilter().filter(s);
                } else if (mViewPager.getCurrentItem() == 1) {
                    usersAdapter.getFilter().filter(s);
                }

                return false;
            }
        });
    } else if (itemId == R.id.main_menu_select_account) {
        Intent editUserIntent = new Intent(this, EditUserActivity.class);
        startActivity(editUserIntent);
    } else if (itemId == R.id.main_menu_preferences) {
        Intent preferencesIntent = new Intent(this, Preferences.class);
        startActivityForResult(preferencesIntent, AppUtils.RETURN_SETUP);
    }

    return super.onOptionsItemSelected(item);
}

From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java

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

    if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_TELEPHONY)) {
        MenuItem phoneMenuItem = menu.findItem(R.id.call_button);
        phoneMenuItem.setVisible(false);
    }//from  w w  w . ja va 2 s  . c  o m

    SearchView searchView = (SearchView) menu.findItem(R.id.search_button).getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            adapter.refresh(newText);
            return true;
        }
    });

    return super.onCreateOptionsMenu(menu);
}

From source file:no.digipost.android.gui.content.ThreadPerTaskExecutor.java

private void setupSearchView() {
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override/*from   w w  w . ja  v a 2  s.c o m*/
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            searchModeOn();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            searchModeOff();
            return true;
        }
    });

    searchView = (android.support.v7.widget.SearchView) searchMenuItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            if (!searchView.isIconified()) {
                searchView.setIconified(true);
            }
            searchMenuItem.collapseActionView();

            search(1, s);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            if (SearchTaskResult.get() != null && !s.equals(SearchTaskResult.get().txt)) {
                SearchTaskResult.set(null);
                mDocView.resetupChildren();
            }
            return true;
        }
    });

    try {

        Field searchField = SearchView.class.getDeclaredField("mSearchButton");
        searchField.setAccessible(true);
        android.widget.ImageView searchBtn = (android.widget.ImageView) searchField.get(searchView);
        searchBtn.setImageResource(R.drawable.white_search_48);
        searchField = SearchView.class.getDeclaredField("mSearchPlate");
        searchField.setAccessible(true);
        LinearLayout searchPlate = (LinearLayout) searchField.get(searchView);
        AutoCompleteTextView searchTextView = (AutoCompleteTextView) searchPlate.getChildAt(0);
        searchTextView.setTextColor(getResources().getColor(R.color.white));
        searchPlate.setBackgroundResource(R.drawable.search_background);
        searchTextView.setHintTextColor(getResources().getColor(R.color.searchbar_grey_hint));
        searchView.setQueryHint(getString(R.string.pdf_search_document));
        android.widget.ImageView searchViewClearButton = (android.widget.ImageView) searchPlate.getChildAt(1);
        searchViewClearButton.setImageResource(R.drawable.ic_clear_white);
    } catch (Exception e) {
        //Empty
    }
}