我在用AutoComplete
小部件。它适用于两个字符搜索,但不适用于一个字符。即使用户只输入一个字符,我也想自动完成工作。
例如,当我输入“1”时,它应该显示所有以“1”开头的列表。
现在它显示 2 个字符的建议列表,例如“12”。
Code:
zip.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
String url = "xxxxxxxxxxxxxxxxxxxxxxx";
String from = "zip";
new GetAutoComplete(url, from).execute();// getting list
}
}
});
ArrayAdapter<Integer> aa = new ArrayAdapter<Integer>(
MyActivity.this, R.layout.list_item_of_zip,
zip_codes);
zip.setAdapter(aa); // zip = autocomplete widget and zip_codes = arrayList
将完成阈值设置为 1。
<AutoCompleteTextView
android:id="@+id/your_id"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:completionThreshold="1" />
或者动态地使用mAutoCompleteTextView.setThreshold(1)
.
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)