Sun*_*nny 34 android autocomplete
我正在使用AutoComplete小部件.它适用于两个字符搜索,但不适用于一个字符.即使用户只输入一个字符,我也希望自动完成工作.
例如,当我输入"1"时,它应显示所有列表以"1"开头.现在显示2个字符的建议列表,例如"12".
码:
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
Run Code Online (Sandbox Code Playgroud)
Jac*_*ips 87
将completionThreshold设置为1.
<AutoCompleteTextView
android:id="@+id/your_id"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:completionThreshold="1" />
Run Code Online (Sandbox Code Playgroud)
或者动态使用它mAutoCompleteTextView.setThreshold(1).
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
使阈值为1,使其从第一个字母开始.你可以这样做:
mAutoCompleteTextView.setThreshold(1);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14841 次 |
| 最近记录: |