我们可以限制在Android的搜索查看的性格的EditText的数量? [英] Can we limit the number of character in edittext of SearchView in Android?
本文介绍了我们可以限制在Android的搜索查看的性格的EditText的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有任何的API来设置的限制没有。在搜索查看字符?
Is there any api to set the limit no. of characters in SearchView ?
推荐答案
的 使用此code会做搜索仅在长度小于或等于5.You可以使它改变相应的喜欢从onQueryTextChange()的时候文本> 5 的
Use this code it will do search only if length is less or equal to 5.You can make it change accordingly like returning true from onQueryTextChange() when text>5.
final SearchView searchView = (SearchView) mSearchMenuItem.getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(mActivity.getSearchComponentName()));
searchView.setIconifiedByDefault(true);
searchView.setSubmitButtonEnabled(true);
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String arg0) {
if(arg0.length()>5){
System.out.println("Text character is more than 5");
searchView.setQuery(arg0.substring(0,5), false);
}
return false;
}
});
这篇关于我们可以限制在Android的搜索查看的性格的EditText的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文