在这个AutoCompleteTextView中,我能够输入所有字母和特殊字符,而不是数字。在棒棒糖及以上观察到问题。在kitkat上工作正常
<AutoCompleteTextView
android:id="@+id/editTextSearchView"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_toLeftOf="@+id/searchclear"
android:layout_marginBottom="20dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="10dp"
android:dropDownHeight="160dp"
android:gravity="center_vertical"
android:hint="Enter Location"
android:imeOptions="actionDone"
android:paddingLeft="10dp"
android:paddingStart="10dp"
android:paddingTop="12dp"
android:singleLine="true"
android:textColor="@color/theme_color"
android:textColorHint="@color/theme_color"
android:textCursorDrawable="@null" />
编辑文本框中使用的textWatcher:
autoCompleteTextView.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void afterTextChanged(Editable editable) {
if(editable.length() > 0)
autoCompleteClearButton.setVisibility(View.VISIBLE);
else
autoCompleteClearButton.setVisibility(View.GONE);
}
});
答案 0 :(得分:1)
try using the android:inputType property in the layout file, set it to number or text
答案 1 :(得分:1)
在xml
中添加此行 <AutoCompleteTextView
android:id="@+id/editTextSearchView"
......
android:inputType="number"
.......
...... />