本文整理匯總了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);
}