android.widget.SearchView Java Examples

The following examples show how to use android.widget.SearchView. 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: NamesFragment.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.names_fragment, menu);

    if (getContext() == null) return;
    SearchManager searchManager = (SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE);
    MenuItem item = menu.findItem(R.id.namesFragment_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 #2
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 #3
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 #4
Source File: SearchActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.searchview_in_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchItem.getActionView();
    setupSearchView(searchItem);

    if (mQuery != null) {
        mSearchView.setQuery(mQuery, false);
    }

    return true;
}
 
Example #5
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 #6
Source File: HomeActivity.java    From io2015-codelabs with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    final SearchView searchView = (SearchView)findViewById(R.id.homeSearch);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Intent intent = new Intent(searchView.getContext(), SearchActivity.class);
            intent.setAction(Intent.ACTION_SEARCH);
            intent.putExtra(SearchManager.QUERY, query);
            startActivity(intent);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
}
 
Example #7
Source File: MainActivity.java    From MalwareBuster with Apache License 2.0 6 votes vote down vote up
private void prepareAppList() {
    final AppListAdapter appListAdapter = new AppListAdapter(MainActivity.this, appList);

    ((ListView) findViewById(R.id.lstApps)).setAdapter(appListAdapter);
    //appListAdapter.getFilter().filter(nameFilter);
    ((SearchView) findViewById(R.id.searchApp)).setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            nameFilter = query;
            appListAdapter.getFilter().filter(nameFilter);
            ((SearchView) findViewById(R.id.searchApp)).clearFocus();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            nameFilter = newText;
            appListAdapter.getFilter().filter(nameFilter);
            return false;
        }

    });
}
 
Example #8
Source File: TypeTextAction.java    From android-test with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public Matcher<View> getConstraints() {
  Matcher<View> matchers = allOf(isDisplayed());
  if (!tapToFocus) {
    matchers = allOf(matchers, hasFocus());
  }

  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
    return allOf(matchers, supportsInputMethods());
  } else {
    // SearchView does not support input methods itself (rather it delegates to an internal text
    // view for input).
    return allOf(matchers, anyOf(supportsInputMethods(), isAssignableFrom(SearchView.class)));
  }
}
 
Example #9
Source File: MapActivity.java    From ETSMobile-Android2 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_map, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_map_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

    return true;
}
 
Example #10
Source File: HomeActivity.java    From search-samples with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    final SearchView searchView = (SearchView)findViewById(R.id.homeSearch);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            Intent intent = new Intent(searchView.getContext(), SearchActivity.class);
            intent.setAction(Intent.ACTION_SEARCH);
            intent.putExtra(SearchManager.QUERY, query);
            startActivity(intent);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
}
 
Example #11
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 #12
Source File: MainListFragment.java    From Android-Applications-Info with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    mProgressDialog = new ProgressDialog(mActivity);
    mProgressDialog.setTitle(R.string.loading_apps);
    mProgressDialog.setCancelable(false);

    ActionBar actionBar = getActivity().getActionBar();
    actionBar.setDisplayShowCustomEnabled(true);

    SearchView searchView = new SearchView(actionBar.getThemedContext());
    searchView.setOnQueryTextListener(this);

    ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    actionBar.setCustomView(searchView, layoutParams);

    if (savedInstanceState != null) {
        int sortBy = savedInstanceState.getInt(INSTANCE_STATE_SORT_BY, -1);
        if (sortBy != -1)
            setSortBy(sortBy);
    }
}
 
Example #13
Source File: SearchActivity.java    From Aria2App with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search, menu);
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.search_search);
    searchItem.setOnActionExpandListener(this);

    searchView = (SearchView) searchItem.getActionView();
    if (searchManager != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
        searchView.setOnCloseListener(this);
        searchView.setOnQueryTextListener(this);
    }

    return true;
}
 
Example #14
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 #15
Source File: SearchActivity.java    From search-samples with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.searchview_in_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    mSearchView = (SearchView) searchItem.getActionView();
    setupSearchView(searchItem);

    if (mQuery != null) {
        mSearchView.setQuery(mQuery, false);
    }

    return true;
}
 
Example #16
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 #17
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 #18
Source File: MainActivity.java    From android-BasicContactables with Apache License 2.0 5 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.main, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager =
            (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView =
            (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(
            searchManager.getSearchableInfo(getComponentName()));

    return true;
}
 
Example #19
Source File: buff_ext.java    From stynico with MIT License 5 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.apk_main, menu);

 search = menu.findItem(R.id.search);//容器
 sv = (SearchView) search.getActionView();//真正的搜索对象
// sv.setIconifiedByDefault(false);//图标显示在外侧
 //sv.setSubmitButtonEnabled(true);//让提交按钮可用
// sv.setQueryHint("请输入应用名");//提示用户信息
 //sv.setOnQueryTextListener(buff_ext.this);//关联提交事件
 
return true;
   }
 
Example #20
Source File: AdvancedActivity.java    From PkRequestManager with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
	getMenuInflater().inflate(R.menu.request_advanced, menu);
	searchView = (SearchView) menu.findItem(R.id.search).getActionView();
	searchView.setOnQueryTextListener(this);
	
	return true;
}
 
Example #21
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 #22
Source File: AppList.java    From CustomText with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_SEARCH && (event.getFlags() & KeyEvent.FLAG_CANCELED) == 0) {
		SearchView searchV = (SearchView) findViewById(R.id.searchApp);
		if (searchV.isShown()) {
			searchV.setIconified(false);
			return true;
		}
	}
	return super.onKeyUp(keyCode, event);
}
 
Example #23
Source File: MainActivity.java    From Qshp with MIT License 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return super.onCreateOptionsMenu(menu);
}
 
Example #24
Source File: ForumActivity.java    From android-discourse with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.uv_forum, menu);
    if (hasActionBar()) {
        menu.findItem(R.id.uv_menu_search).setOnActionExpandListener(new SearchExpandListener(this));
        SearchView search = (SearchView) menu.findItem(R.id.uv_menu_search).getActionView();
        search.setOnQueryTextListener(new SearchQueryListener(this));
    } else {
        menu.findItem(R.id.uv_menu_search).setVisible(false);
    }
    menu.findItem(R.id.uv_new_idea).setVisible(Session.getInstance().getConfig().shouldShowPostIdea());
    return true;
}
 
Example #25
Source File: ManCacheFragment.java    From Man-Man with GNU General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = inflater.inflate(R.layout.fragment_cache_browse, container, false);

    mSearchCache = (SearchView) root.findViewById(R.id.cache_search_edit);
    mSearchCache.setOnQueryTextListener(new SearchInCacheListener());
    mCacheList = (ListView) root.findViewById(R.id.cached_pages_list);
    mCacheList.setOnItemClickListener(this);
    getLoaderManager().initLoader(MainPagerActivity.CACHE_RETRIEVER_LOADER, null, mCacheBrowseCallback);
    LocalBroadcastManager.getInstance(getActivity()).registerReceiver(mBroadcastHandler, new IntentFilter(MainPagerActivity.DB_CHANGE_NOTIFY));
    return root;
}
 
Example #26
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 #27
Source File: LoaderCustom.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 #28
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 #29
Source File: MainActivity.java    From ampdroid with MIT License 5 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.main, menu);

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

	return true;
}
 
Example #30
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);
}