gpt4 book ai didi

android - 在搜索 View 中搜索后无法隐藏键盘

转载 作者:行者123 更新时间:2023-11-30 00:40:18 25 4
gpt4 key购买 nike

    final android.support.v7.widget.SearchView searchView = (android.support.v7.widget.SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

searchView.setFocusable(false);

searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(searchView.getWindowToken(),
InputMethodManager.RESULT_UNCHANGED_SHOWN);


if (query.length() >= 3) {

String urlfilter = "http://frenzinsoftwares.in/alert/apis/search.php" +
"?key=" + query.toString();

if (isNetworkAvailable()) {
new GetMyAppliancesfilter().execute(urlfilter);
} else {
Toast.makeText(ListActivity.this, "No Network Available",
Toast.LENGTH_LONG).show();
}
}

return false;
}

@Override
public boolean onQueryTextChange(String newText) {


if (isSearch) {
if (isNetworkAvailable()) {

if (newText.length() == 0) {

String url2 = "http://frenzinsoftwares.in/alert/apis/filter_by_category.php" +
"?category=" + selcategory.toString() +
"&city=" + 1;

new Filtercategory().execute(url2);
}
} else {
Toast.makeText(ListActivity.this, "No Network Available",
Toast.LENGTH_LONG).show();
}

} else {

isSearch = true;

}

if (newText.length() >= 3) {

String urlfilter = "http://frenzinsoftwares.in/alert/apis/search.php" +
"?key=" + newText.toString();

if (isNetworkAvailable()) {
new GetMyAppliancesfilter().execute(urlfilter);
} else {
Toast.makeText(ListActivity.this, "No Network Available",
Toast.LENGTH_LONG).show();
}
}
return false;


}
});

最佳答案

在 onQueryTextSubmit 中试试这个:

searchView.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager) searchView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(searchView.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}, 50);

尝试以下:

searchView.clearFocus();
if (getCurrentFocus()!=null){
InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
}

关于android - 在搜索 View 中搜索后无法隐藏键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42664976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com