是否有任何api设置限制否。 SearchView中的字符?
答案 0 :(得分:5)
使用此代码只有在长度小于或等于5时才会进行搜索。您可以相应地进行搜索,例如在文本> 5时从onQueryTextChange()返回true。
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;
}
});
答案 1 :(得分:5)
EditText et = (EditText)searchView.findViewById(searchView.getContext().getResources()
.getIdentifier("android:id/search_src_text", null, null));
et.setFilters(new InputFilter[] { new InputFilter.LengthFilter({max_text_length}) });
答案 2 :(得分:-1)
EditText et = new EditText(this);
int maxLength = 3;
InputFilter[] FilterArray = new InputFilter[1];
FilterArray[0] = new InputFilter.LengthFilter(maxLength);
et.setFilters(FilterArray);
答案 3 :(得分:-3)
在xml Layout中试试这个..
android:maxLength="20" //20 is number of characters.
它可能对你有所帮助..