本文整理汇总了Java中android.support.v7.widget.SearchView.setOnSearchClickListener方法的典型用法代码示例。如果您正苦于以下问题:Java SearchView.setOnSearchClickListener方法的具体用法?Java SearchView.setOnSearchClickListener怎么用?Java SearchView.setOnSearchClickListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.SearchView
的用法示例。
在下文中一共展示了SearchView.setOnSearchClickListener方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.toolbar_menu, menu);
MenuItem searchItem = menu.findItem(R.id.search);
searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
mSearchAutoComplete = searchView.findViewById(R.id.search_src_text);
searchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switchLayout();
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
switchLayout();
return false;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
final List<General> filteredList = filter(DataSupport.findAll(General.class), newText);
adapter.setNewData(filteredList);
adapter.notifyDataSetChanged();
return false;
}
});
return super.onCreateOptionsMenu(menu);
}
示例2: onCreateOptionsMenu
import android.support.v7.widget.SearchView; //导入方法依赖的package包/类
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("dark_theme", false))
menu.findItem(R.id.Theme).setTitle("今夜白");
final MenuItem searchItem = menu.findItem(R.id.toolbar_search);
searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
MenuItemCompat.getActionView(searchItem);
searchView.setQueryHint("搜索书籍或者作者");
searchView.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchView.setQuery(lastKeyWords, false);
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//处理搜索结果
try {
lastKeyWords = query;
Runtime runtime = Runtime.getRuntime();
runtime.exec("input keyevent " + KeyEvent.KEYCODE_BACK);
runtime.exec("input keyevent " + KeyEvent.KEYCODE_BACK);
setTitle("搜索:" + query);
for (BaseFragment fragment : mPagerAdapter.getFragments()) {
fragment.startSearch(query);
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
return super.onCreateOptionsMenu(menu);
}