Is there any api to set the limit no. of characters in SearchView ?
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}) });
I am using following code snippet:
TextView et = (TextView) searchView.findViewById(R.id.search_src_text);
et.setFilters(new InputFilter[]{new InputFilter.LengthFilter(10)});
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;
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With