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:org.jitsi.android.gui.contactlist.ContactListFragment.java

private void bindSearchListener() {
    if (searchItem != null) {
        SearchView searchView = (SearchView) searchItem.getActionView();

        SearchViewListener listener = new SearchViewListener();
        searchView.setOnQueryTextListener(listener);
        searchView.setOnCloseListener(listener);
    }/*from  w  w  w  . j  a va  2  s  .  c om*/
}

From source file:br.com.GUI.perfil.BuscarUsuario.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.buscar_usuario, menu);

    final SearchView searchView = new SearchView(this.getActionBar().getThemedContext());
    searchView.setQueryHint("Search");

    menu.add(Menu.NONE, Menu.NONE, 1, "@string").setIcon(android.R.drawable.ic_menu_search)
            .setActionView(searchView)//w w  w. j  a v  a2  s  .c  o m
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            /* if (newText.length() > 0) {
                if(pref.getString("tipo", null).equals("personal")){
                   pesquisarAluno(newText.toString());
                }else if(pref.getString("tipo", null).equals("aluno")){
                   pesquisarPersonal(newText.toString());
                }
                    
             } else {
                if(pref.getString("tipo", null).equals("personal")){
                   pesquisarAluno("");
                }else if(pref.getString("tipo", null).equals("aluno")){
                   pesquisarPersonal("");
                }
                        
            }*/
            return false;
        }

        @Override
        public boolean onQueryTextSubmit(String arg0) {
            if (pref.getString("tipo", null).equals("personal")) {
                pesquisarAluno(arg0);
            } else if (pref.getString("tipo", null).equals("aluno")) {
                pesquisarPersonal(arg0);
            }

            return false;
        }
    });
    return true;
}

From source file:com.owncloud.android.ui.fragment.SearchShareesFragment.java

/**
 * {@inheritDoc}/* ww  w  .  j  av  a 2s .  co  m*/
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.search_users_groups_layout, container, false);

    // Get the SearchView and set the searchable configuration
    SearchView searchView = (SearchView) view.findViewById(R.id.searchView);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()) // assumes parent activity is the searchable activity
    );
    searchView.setIconifiedByDefault(false); // do not iconify the widget; expand it by default

    searchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI); // avoid fullscreen with softkeyboard

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Log_OC.v(TAG, "onQueryTextSubmit intercepted, query: " + query);
            return true; // return true to prevent the query is processed to be queried;
            // a user / group will be picked only if selected in the list of suggestions
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false; // let it for the parent listener in the hierarchy / default behaviour
        }
    });

    return view;
}

From source file:com.andrew.apollo.ui.activities.BaseActivity.java

/**
 * {@inheritDoc}//www  . j av  a  2  s  . c o m
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Search view
    getMenuInflater().inflate(R.menu.search, menu);
    // Settings
    getMenuInflater().inflate(R.menu.activity_base, menu);
    // Theme the search icon
    mResources.setSearchIcon(menu);

    final SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Add voice search
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
    searchView.setSearchableInfo(searchableInfo);
    // Perform the search
    searchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(final String query) {
            // Open the search activity
            NavUtils.openSearch(BaseActivity.this, query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(final String newText) {
            // Nothing to do
            return false;
        }
    });
    return super.onCreateOptionsMenu(menu);
}

From source file:de.tap.easy_xkcd.Activities.SearchResultsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search_results, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//w w w. j a v  a  2  s. c  o m
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (task != null) {
                task.cancel(true);
            }
            task = new searchTask();
            task.execute(newText);
            return false;
        }
    });

    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(view, 0);
            }
            searchView.requestFocus();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return true;
        }
    });
    return true;
}

From source file:com.example.lowviscam.GalleryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    if (isLight == true) {
        inflater.inflate(R.menu.gallery, menu);
    } else {//from  w ww  . j  a va2  s.  c  o m
        inflater.inflate(R.menu.gallery_dark, menu);
    }

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            search(query);
            // First image toast
            String firstResult;
            if (numSearchResults == 0) {
                firstResult = "No results found for  " + query + ".";
            } else {
                firstResult = "The first image result is titled " + tagList[0];
            }

            SpannableString s = new SpannableString(firstResult);
            s.setSpan(new TypefaceSpan(GalleryActivity.this, "APHont-Regular_q15c.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            Toast.makeText(GalleryActivity.this, s, Toast.LENGTH_LONG).show();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
                search("");
            }

            return true;
        }

        public void search(String query) {
            // hide keyboard
            InputMethodManager inputManager = (InputMethodManager) GalleryActivity.this
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(GalleryActivity.this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            // Fetch the {@link LayoutInflater} service so that new views can be created
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            // Find the {@link GridView} that was already defined in the XML layout
            GridView gridView = (GridView) findViewById(R.id.grid);
            try {
                gridView.setAdapter(new CouponAdapter(inflater, createSearchedCoupons(query)));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    });

    return true;
    //return super.onCreateOptionsMenu(menu);
}

From source file:com.wearapp.PickFriendsActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    //Log.w(TAG, "IN createing Search friends OptionsMenu");
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.options_menu, menu);
    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(//from  w w w  .  j av  a  2 s .  c o m
            searchManager.getSearchableInfo(new ComponentName("com.wearapp", "com.wearapp.HistoryActivity")));
    //searchView.setSearchableInfo(searchManager.getSearchableInfo(this.getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    searchView.setQueryHint(getResources().getString(R.string.search_friend_hint));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            // TODO Auto-generated method stub
            return false;
        }

        @Override
        public boolean onQueryTextChange(String keyword) {
            // TODO Auto-generated method stub         

            selectedUsers.addAll(selectedUsers_temp1);
            //TODO need update FacebookSDK to 2.6 version 
            friendPickerFragment.setSelection(selectedUsers);

            searchterm = keyword;
            friendPickerFragment.setFilter(new GraphObjectFilter<GraphUser>() {
                @Override
                public boolean includeItem(GraphUser graphObject) {
                    // TODO Auto-generated method stub                               
                    Pattern p = Pattern.compile(searchterm, Pattern.CASE_INSENSITIVE);
                    Matcher m = p.matcher(graphObject.getName());
                    if (m.find()) {
                        return true;
                    }
                    return false;
                }
            });

            friendPickerFragment.loadData(true);

            return false;
        }

    });

    return true;
}

From source file:se.eliga.aves.birdlist.BirdListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.main_menu, menu);

    MenuItem item = menu.findItem(R.id.species_search);
    SearchView searchView = new SearchView(((MainActivity) getActivity()).getActionBar().getThemedContext());
    MenuItemCompat.setShowAsAction(item,
            MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW | MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    MenuItemCompat.setActionView(item, searchView);
    final BirdListAdapter birdListAdapter = (BirdListAdapter) getListAdapter();
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override//from   w  w w . j  a  va 2 s  . co  m
        public boolean onClose() {
            birdListAdapter.setFilterString(null);
            birdListAdapter.refresh();
            birdListAdapter.notifyDataSetChanged();
            return false;
        }
    });
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            birdListAdapter.setFilterString(query);
            birdListAdapter.refresh();
            birdListAdapter.notifyDataSetChanged();
            return true;
        }

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

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();// ww  w.  j  a v a 2 s  .  co m
        } 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:de.tap.easy_xkcd.Activities.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from  w  w w  . j  a  v  a2 s .c om
        public boolean onQueryTextSubmit(String query) {
            MenuItem searchMenuItem = getSearchMenuItem();
            searchMenuItem.collapseActionView();
            searchView.setQuery("", false);
            //Hide Keyboard
            View view = MainActivity.this.getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(view, 0);
            }
            searchView.requestFocus();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return true;
        }
    });
    if (prefHelper.hideDonate())
        menu.findItem(R.id.action_donate).setVisible(false);
    return true;
}