我有一个AutoCompleteTextView
,但我希望它使用用户以前的输入,而不是我说要完成的某些字符串,所以问题是:我该怎么做?
If you want your AutoCompleteTextView
to show suggestions based on some string rather than taking input from user then just call:
myAutoCompleteTextView.setText("cou", true);
and then in case drop down is not shown, call:
myAutoCompleteTextView.showDropDown();
AutoCompleteTextView
do not propose this feature by default but you could implement it yourself.
AutoCompleteTextView
. Example to set an adpatater with pre defined string array from Google doc:
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
public class CountriesActivity extends Activity {
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.countries);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, COUNTRIES);
AutoCompleteTextView textView = (AutoCompleteTextView)
findViewById(R.id.countries_list);
textView.setAdapter(adapter);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
}
Instead to use a fix array COUNTRIES
like in the example above, use a String array retrieved from the database,
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.