我有一个AutoCompleteTextView,我想在它上面设置一个过滤器,但问题是当我去输入内容时,文本框只允许我输入一个字符。如果我从代码中删除textView.setFilters,那么它就可以正常工作,但我没有任何过滤器。我还尝试在我的xml文件中使用android:textAllCaps="true",但它不起作用。希望能得到帮助,谢谢。
我的代码:
我的代码:
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.textfield);
String[] MyArray = getResources().getStringArray(R.array.myarray);
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, MyArray);
textView.setFilters(new InputFilter[]{new InputFilter.AllCaps(), new InputFilter.LengthFilter(40)});
textView.setAdapter(adapter);
Xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".myactivity">
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/textfield"
android:hint="Search..."/>
<Button
android:id="@+id/btn"
android:onClick="buttonClickHandler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Do something"
android:layout_toRightOf="@+id/textfield"/>
</RelativeLayout>
new InputFilter.AllCaps()
。我的理解是,这个过滤器不允许你输入小写字母。尝试在你的TextView中输入大写字母。 - Vivek Mishra