是否有可能通过资源通过XML向AutoCompleteTextView
提供值,因此无需在代码中设置适配器?
我想将AutoCompleteTextView
用作exposed dropdown menu的一部分,因此所有值应立即显示,并且不进行任何过滤。另外,所有要显示的值在编译时都是已知的。
我想您可以通过使用Resource中的列表并在适配器传递的AutoCompleteTextView中实现它来实现。
请参见此处的示例:
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);
}
Resources res = getResources();
private static final String[] COUNTRIES = res.getStringArray(R.array.planets_array);
}
希望这可以帮助您或任何其他人。