本文整理汇总了Java中android.widget.SearchView类的典型用法代码示例。如果您正苦于以下问题:Java SearchView类的具体用法?Java SearchView怎么用?Java SearchView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SearchView类属于android.widget包,在下文中一共展示了SearchView类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateOptionsMenu
import android.widget.SearchView; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
MenuInflater menuInflater = new MenuInflater(rootView.getContext());
menuInflater.inflate(R.menu.menu_ventas_lista, menu);
MenuItem item = menu.findItem(R.id.item_buscar);
SearchView searchView = (SearchView)item.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
super.onCreateOptionsMenu(menu, inflater);
}
开发者ID:EdwardAlexis,项目名称:Sistema-de-Comercializacion-Negocios-Jhordan,代码行数:21,代码来源:ViewPagerVentasLista.java
示例2: configureFolderSearchView
import android.widget.SearchView; //导入依赖的package包/类
private void configureFolderSearchView(Menu menu) {
final MenuItem folderMenuItem = menu.findItem(R.id.filter_folders);
final SearchView folderSearchView = (SearchView) folderMenuItem.getActionView();
folderSearchView.setQueryHint(getString(R.string.folder_list_filter_hint));
folderSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
folderMenuItem.collapseActionView();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
mAdapter.getFilter().filter(newText);
return true;
}
});
}
示例3: onCreateOptionsMenu
import android.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.search_menu, menu);
MenuItem search = menu.findItem(R.id.search);
SearchView searchView = (SearchView) search.getActionView();
initQueryTextListener(searchView);
return true;
}
示例4: initQueryTextListener
import android.widget.SearchView; //导入依赖的package包/类
private void initQueryTextListener(SearchView searchView) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
IconsSearchUtils.filter(newText, matchingIcons, allIcons, mGridAdapter);
return true;
}
});
}
示例5: onCreateOptionsMenu
import android.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menuInflater = getMenuInflater();
menuInflater.inflate(R.menu.menu_main, menu);
menu.findItem(R.id.item_show_system).setChecked(mSharedPreferences.getBoolean(PREF_SHOW_SYSTEM, false));
menu.findItem(R.id.item_show_toast).setChecked(mSharedPreferences.getBoolean(PREF_TOAST, true));
mSearchView = (SearchView) menu.findItem(R.id.item_search).getActionView();
mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
filterApps(app -> app.name.toLowerCase().contains(query.toLowerCase()) || app.packageName.toLowerCase().contains(query.toLowerCase()));
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
filterApps(app -> app.name.toLowerCase().contains(newText.toLowerCase()) || app.packageName.toLowerCase().contains(newText.toLowerCase()));
return true;
}
});
return true;
}
示例6: onCreateOptionsMenu
import android.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
searchItem = menu.findItem(R.id.search);
searchView = (SearchView) searchItem.getActionView();
if (searchView != null)
{
searchView.setSubmitButtonEnabled(true);
searchView.setImeOptions(EditorInfo.IME_ACTION_GO);
searchView.setOnQueryTextListener(new QueryTextListener());
}
return true;
}
示例7: onCreateOptionsMenu
import android.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu_main, 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(searchManager.getSearchableInfo(getComponentName()));
searchView.setIconifiedByDefault(true); // Do not iconify the widget; expand it by default
searchView.setQueryHint(getResources().getString(R.string.search_hint));
return true;
}
示例8: onResume
import android.widget.SearchView; //导入依赖的package包/类
@Override
public void onResume() {
super.onResume();
List<File> containers = FileUtils.getContainers(getActivity());
final ContainerListAdapter containerListAdapter = new ContainerListAdapter(getActivity(), containers);
setListAdapter(containerListAdapter);
SearchView searchView = (SearchView) getActivity().findViewById(R.id.listSearch);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
containerListAdapter.getFilter().filter(newText);
return false;
}
});
searchView.setQuery("", false);
getActivity().findViewById(R.id.content_browse_containers).requestFocus();
}
示例9: onCreateOptionsMenu
import android.widget.SearchView; //导入依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
SearchView searchView = new SearchView(this);
searchView.setSearchableInfo(((SearchManager) getSystemService(Context.SEARCH_SERVICE)).getSearchableInfo(getComponentName()));
searchView.setOnQueryTextListener(this);
menu.add(android.R.string.search_go)
.setIcon(android.R.drawable.ic_menu_search)
.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW + MenuItem.SHOW_AS_ACTION_ALWAYS)
.setActionView(searchView)
.setOnActionExpandListener(this);
if (mShowTint) {
MenuItem item = menu.add(R.string.wc_tint);
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
item.setActionView(R.layout.ab_color_btn);
ColorButton cb = (ColorButton) item.getActionView().findViewById(R.id.btn_tint);
cb.setColor(mAdapter.mColorFilter);
cb.setOnColorChangeListener(this, true);
}
return true;
}
示例10: onCreateView
import android.widget.SearchView; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_home_list, container, false);
final ListView recipeList = (ListView) view.findViewById(R.id.list_view);
recipeList.setAdapter(new RecipeListAdapter(getActivity(), mRecipes));
// Configure list for testing
recipeList.setTag(R.id.test_tag_recipe_list, "Recipe List");
// Search
mSearchView = (SearchView) view.findViewById(R.id.search);
mSearchView.setOnQueryTextListener(new SearchHandler());
// Empty view, shown when list is empty
final TextView emptyView = (TextView) view.findViewById(R.id.empty_list_view);
emptyView.setText(R.string.no_recipes);
if (mRecipes.isEmpty()) {
emptyView.setVisibility(View.VISIBLE);
} else {
emptyView.setVisibility(View.INVISIBLE);
}
mRecipes.addOnListChangedCallback(new ListEmptyViewManager(emptyView));
return view;
}
示例11: fromView
import android.widget.SearchView; //导入依赖的package包/类
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.onComplete();
return true;
}
@Override
public boolean onQueryTextChange(String text) {
subject.onNext(text);
return true;
}
});
return subject;
}
示例12: onCreateOptionsMenu
import android.widget.SearchView; //导入依赖的package包/类
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
searchView.setIconifiedByDefault(false);
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
model.search(query);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return true;
}
});
}
示例13: configureSearchWidget
import android.widget.SearchView; //导入依赖的package包/类
@Override
public void configureSearchWidget(
Activity activity, MenuItem menuItem, final TrackController trackController) {
SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
searchView.setQueryRefinementEnabled(true);
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// Hide and show trackController when search widget has focus/no focus
if (trackController != null) {
if (hasFocus) {
trackController.hide();
} else {
trackController.show();
}
}
}
});
}
示例14: linkSearchViewToSearcher
import android.widget.SearchView; //导入依赖的package包/类
private void linkSearchViewToSearcher(@NonNull final SearchViewFacade searchView) {
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
// SearchView.OnQueryTextListener
@Override
public boolean onQueryTextSubmit(String query) {
EventBus.getDefault().post(new QueryTextSubmitEvent());
// Nothing to do: the search has already been performed by `onQueryTextChange()`.
// We do try to close the keyboard, though.
searchView.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
EventBus.getDefault().post(new QueryTextChangeEvent(newText, searchView.getSearchView()));
if (newText.length() == 0 && !searchOnEmptyString) {
return true;
}
searcher.setQuery(searcher.getQuery().setQuery(searchView.getQuery().toString()))
.search();
return true;
}
});
}
示例15: setOnQueryTextListener
import android.widget.SearchView; //导入依赖的package包/类
/**
* Sets a listener for user actions within the SearchView.
*
* @param listener the listener object that receives callbacks when the user performs
* actions in the SearchView such as clicking on buttons or typing a query.
*/
public void setOnQueryTextListener(@NonNull final SearchView.OnQueryTextListener listener) {
if (searchView != null) {
searchView.setOnQueryTextListener(listener);
} else if (supportView != null) {
supportView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
@Override public boolean onQueryTextSubmit(String query) {
return listener.onQueryTextSubmit(query);
}
@Override public boolean onQueryTextChange(String newText) {
return listener.onQueryTextChange(newText);
}
});
} else {
throw new IllegalStateException(ERROR_NO_SEARCHVIEW);
}
}