Java Code Examples for android.widget.SearchView#setOnQueryTextListener()

The following examples show how to use android.widget.SearchView#setOnQueryTextListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Friends.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
	if (getAdapter() != null && getAdapter().getCount() > 0)
	{
		// Create the search view
		SearchView searchView = new SearchView(((FragmentActivity) getActivity()).getActionBar()
				.getThemedContext());
		searchView.setQueryHint("Search for friends");
		searchView.setOnQueryTextListener(this);

		menu.add("Search").setIcon(AttrUtil.getResourceId(getActivity(), R.attr.searchIcon))
				.setActionView(searchView)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
	}

	super.onCreateOptionsMenu(menu, inflater);
}
 
Example 2
Source File: FollowedPeople.java    From Klyph with MIT License 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
	if (getAdapter() != null && getAdapter().getCount() > 0)
	{
		// Create the search view
		SearchView searchView = new SearchView(((FragmentActivity) getActivity()).getActionBar()
				.getThemedContext());
		searchView.setQueryHint("Search for people");
		searchView.setOnQueryTextListener(this);

		menu.add("Search").setIcon(AttrUtil.getResourceId(getActivity(), R.attr.searchIcon))
				.setActionView(searchView)
				.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
	}

	super.onCreateOptionsMenu(menu, inflater);
}
 
Example 3
Source File: AlarmListActivity.java    From boilr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	// Inflate the menu; this adds items to the action bar if it is present.
	getMenuInflater().inflate(R.menu.alarm_list, menu);
	mSearchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
	mSearchView.setOnQueryTextListener(queryListener);
	/*
	 * Hack to keep the search icon consistent between themes. Without this
	 * the icon for the light theme is smaller than the one on the dark
	 * theme. By just_user on Stack Overflow http://stackoverflow.com/questions/10445760/how-to-change-the-default-icon-on-the-searchview-to-be-use-in-the-action-bar-on/18360563#18360563
	 */
	int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
	ImageView view = (ImageView) mSearchView.findViewById(searchImgId);
	TypedArray ta = obtainStyledAttributes(attrs);
	view.setImageResource(ta.getResourceId(0, R.drawable.ic_action_remove_light));
	return super.onCreateOptionsMenu(menu);
}
 
Example 4
Source File: GamesFragment.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.games_fragment, menu);

    if (getContext() == null) return;
    SearchManager searchManager = (SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE);
    MenuItem item = menu.findItem(R.id.gamesFragment_search);
    item.setOnActionExpandListener(this);

    if (searchManager != null && getActivity() != null) {
        searchView = (SearchView) item.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setIconifiedByDefault(false);
        searchView.setOnCloseListener(this);
        searchView.setOnQueryTextListener(this);
    }
}
 
Example 5
Source File: ManPageSearchFragment.java    From Man-Man with GNU General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    cachedChapters = Utils.parseStringArray(getActivity(), R.array.man_page_chapters);

    // Inflate the layout for this fragment
    View root = inflater.inflate(R.layout.fragment_man_page_search, container, false);
    mSearchView = (SearchView) root.findViewById(R.id.query_edit);
    mSearchView.setOnQueryTextListener(new SearchQueryTextListener());
    mSearchImage = (ImageView) mSearchView.findViewById(Resources.getSystem().getIdentifier("search_mag_icon", "id", "android"));
    mSearchDefaultDrawable = mSearchImage.getDrawable();
    mSearchList = (ListView) root.findViewById(R.id.search_results_list);

    mUiHandler = new Handler();
    getLoaderManager().initLoader(MainPagerActivity.SEARCH_COMMAND_LOADER, null, mSearchCommandCallback);
    getLoaderManager().initLoader(MainPagerActivity.SEARCH_ONELINER_LOADER, null, mSearchOneLinerCallback);
    return root;
}
 
Example 6
Source File: RxSearchObservable.java    From RxJava2-Android-Samples with Apache License 2.0 6 votes vote down vote up
public static Observable<String> fromView(SearchView searchView) {

        final PublishSubject<String> subject = PublishSubject.create();

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String s) {
                subject.onNext(s);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String text) {
                subject.onNext(text);
                return true;
            }
        });

        return subject;
    }
 
Example 7
Source File: TaskListActivity.java    From friendly-plans with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.plan_list_menu, menu);
    MenuItem searchViewItem = menu.findItem(R.id.menu_search);
    searchView = (SearchView) searchViewItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            refreshList(query, selectedTypeId);
            return false;
        }

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

    return true;
}
 
Example 8
Source File: PlanListActivity.java    From friendly-plans with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.plan_list_menu, menu);
    MenuItem searchViewItem = menu.findItem(R.id.menu_search);
    searchView = (SearchView) searchViewItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            refreshList(query);
            return false;
        }

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

    return true;
}
 
Example 9
Source File: MainActivity.java    From dttv-android with GNU General Public License v3.0 5 votes vote down vote up
protected void createActionMode(int mode, Menu menu) {
     menu.clear();
     switch (mode) {
         case Constant.LOCAL_VIDEO:
             SearchView searchView = new SearchView(this);
             searchView.setMaxWidth(600);
             searchView.setQueryHint("input words");
             searchView.setOnQueryTextListener(this);
             searchView.setOnSuggestionListener(this);

/*menu.add("Search").setIcon(R.drawable.dt_action_search_icon)
.setActionView(searchView)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);*/
             menu.add("Refresh").setIcon(R.drawable.dt_action_refresh_icon)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

             menu.add("Setting").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
             break;
         case Constant.LOCAL_AUDIO:
             menu.add("Plus").setIcon(R.drawable.dt_action_plus_icon)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
             menu.add("Setting").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
             break;
         case Constant.LOCAL_FILE:
             menu.add("Refresh").setIcon(R.drawable.dt_action_refresh_icon)
                     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
             menu.add("Setting").setShowAsAction(MenuItem.SHOW_AS_ACTION_WITH_TEXT);
             break;
     }
 }
 
Example 10
Source File: ProgrammaticAutocompleteToolbarActivity.java    From android-places-demos with Apache License 2.0 5 votes vote down vote up
private void initSearchView(SearchView searchView) {
    searchView.setQueryHint(getString(R.string.search_a_place));
    searchView.setIconifiedByDefault(false);
    searchView.setFocusable(true);
    searchView.setIconified(false);
    searchView.requestFocusFromTouch();
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            progressBar.setIndeterminate(true);

            // Cancel any previous place prediction requests
            handler.removeCallbacksAndMessages(null);

            // Start a new place prediction request in 300 ms
            handler.postDelayed(() -> {
                getPlacePredictions(newText);
            }, 300);
            return true;
        }
    });
}
 
Example 11
Source File: MainActivity.java    From xunmi_android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    searchView = (SearchView)menu.findItem(R.id.searchView).getActionView();
    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView v = (ImageView) searchView.findViewById(searchImgId);
    v.setImageResource(R.drawable.search); 
    searchView.setOnQueryTextListener(MainActivity.this);
    searchView.setSubmitButtonEnabled(true);
		
    searchView.setOnCloseListener(MainActivity.this);
    return true;
}
 
Example 12
Source File: CursorFragment.java    From V.FlyoutTest with MIT License 5 votes vote down vote up
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM
            | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    SearchView sv = new SearchView(getActivity());
    sv.setOnQueryTextListener(this);
    item.setActionView(sv);
}
 
Example 13
Source File: DialtactsActivity.java    From coursera-android with MIT License 5 votes vote down vote up
private void prepareSearchView() {
    final View searchViewLayout =
            getLayoutInflater().inflate(R.layout.dialtacts_custom_action_bar, null);
    mSearchView = (SearchView) searchViewLayout.findViewById(R.id.search_view);
    mSearchView.setOnQueryTextListener(mPhoneSearchQueryTextListener);
    mSearchView.setOnCloseListener(mPhoneSearchCloseListener);
    // Since we're using a custom layout for showing SearchView instead of letting the
    // search menu icon do that job, we need to manually configure the View so it looks
    // "shown via search menu".
    // - it should be iconified by default
    // - it should not be iconified at this time
    // See also comments for onActionViewExpanded()/onActionViewCollapsed()
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setQueryHint(getString(R.string.hint_findContacts));
    mSearchView.setIconified(false);
    mSearchView.setOnQueryTextFocusChangeListener(new OnFocusChangeListener() {
        @Override
        public void onFocusChange(View view, boolean hasFocus) {
            if (hasFocus) {
                showInputMethod(view.findFocus());
            }
        }
    });

    if (!ViewConfiguration.get(this).hasPermanentMenuKey()) {
        // Filter option menu should be shown on the right side of SearchView.
        final View filterOptionView = searchViewLayout.findViewById(R.id.search_option);
        filterOptionView.setVisibility(View.VISIBLE);
        filterOptionView.setOnClickListener(mFilterOptionClickListener);
    }

    getActionBar().setCustomView(searchViewLayout,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
 
Example 14
Source File: SearchableActivity.java    From RhymeMusic with Apache License 2.0 5 votes vote down vote up
private void initComponents()
    {
        application = (MusicApplication) getApplication();

        /*搜索结果为空时,显示的提示信息*/
        textTips = (TextView) findViewById(R.id.text_tips);

        /*按钮类组件初始化*/
        searchBack = (ImageButton) findViewById(R.id.image_search_back);
        searchOption = (ImageButton) findViewById(R.id.image_search_option);
        searchBack.setOnClickListener(this);
        searchOption.setOnClickListener(this);

        /*列表组件初始化*/
        listView = (ListView) findViewById(R.id.list_search_result);
        listView.setOnItemClickListener(this);
        listView.setVisibility(View.INVISIBLE);
        loadData();

        /*搜索组件初始化*/
        searchView = (SearchView) findViewById(R.id.view_search);
        searchView.setOnQueryTextListener(this);
        searchView.onActionViewExpanded(); // 默认出现点击输入状态
        searchView.setFocusable(false);
        searchView.clearFocus();
//        searchView.setSubmitButtonEnabled(true);

    }
 
Example 15
Source File: SearchShareesFragment.java    From Cirrus_depricated with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@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;
}
 
Example 16
Source File: ExcludeAppsFragment.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.allowed_apps, menu);

    SearchView searchView = (SearchView) menu.findItem( R.id.app_search_widget ).getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            mListView.setFilterText(query);
            mListView.setTextFilterEnabled(true);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mListView.setFilterText(newText);
            if (TextUtils.isEmpty(newText))
                mListView.setTextFilterEnabled(false);
            else
                mListView.setTextFilterEnabled(true);

            return true;
        }
    });
    searchView.setOnCloseListener(() -> {
        mListView.clearTextFilter();
        mListAdapter.getFilter().filter("");
        return false;
    });

    super.onCreateOptionsMenu(menu, inflater);
}
 
Example 17
Source File: LoaderCursor.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    SearchView sv = new SearchView(getActivity());
    sv.setOnQueryTextListener(this);
    item.setActionView(sv);
}
 
Example 18
Source File: ProgrammaticAutocompleteToolbarActivity.java    From android-places-demos with Apache License 2.0 5 votes vote down vote up
private void initSearchView(SearchView searchView) {
    searchView.setQueryHint(getString(R.string.search_a_place));
    searchView.setIconifiedByDefault(false);
    searchView.setFocusable(true);
    searchView.setIconified(false);
    searchView.requestFocusFromTouch();
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            progressBar.setIndeterminate(true);

            // Cancel any previous place prediction requests
            handler.removeCallbacksAndMessages(null);

            // Start a new place prediction request in 300 ms
            handler.postDelayed(() -> {
                getPlacePredictions(newText);
            }, 300);
            return true;
        }
    });
}
 
Example 19
Source File: ActivityMain.java    From XPrivacy with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
	MenuInflater inflater = getMenuInflater();
	if (inflater != null && PrivacyService.checkClient()) {
		// Inflate menu
		inflater.inflate(R.menu.main, menu);

		// Searchable
		SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));
		if (searchView != null) {
			searchView.setIconifiedByDefault(false);

			searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
				@Override
				public boolean onQueryTextChange(String newText) {
					searchQuery = newText;
					applyFilter();
					return true;
				}

				@Override
				public boolean onQueryTextSubmit(String query) {
					searchQuery = query;
					applyFilter();
					return true;
				}
			});
			searchView.setOnCloseListener(new SearchView.OnCloseListener() {
				@Override
				public boolean onClose() {
					searchQuery = "";
					applyFilter();
					return true;
				}
			});
		}

		return true;
	} else
		return false;
}
 
Example 20
Source File: CHMFrag.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) {
	super.onCreateOptionsMenu(menu, inflater);
	inflater.inflate(R.menu.menu_chm, menu);

       SearchManager searchManager =
		(SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
       SearchView searchView =
		(SearchView) menu.findItem(R.id.menu_search).getActionView();
       searchView.setSearchableInfo(
		searchManager.getSearchableInfo(activity.getComponentName()));
       searchView.setOnCloseListener(new SearchView.OnCloseListener() {
			@Override
			public boolean onClose() {
				webview.clearMatches();
				return false;
			}
		});
       searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
			@Override
			public boolean onQueryTextSubmit(String query) {
				return false;
			}

			@Override
			public boolean onQueryTextChange(String newText) {
				webview.findAllAsync(newText);
				try {
					for (Method m : WebView.class.getDeclaredMethods()) {
						if (m.getName().equals("setFindIsUp")) {
							m.setAccessible(true);
							m.invoke((webview), true);
							break;
						}
					}
				} catch (Exception ignored) {
				}
				return false;
			}
		});
       
   }