如何从Android中以编程方式选择Android Word建议?
答案 0 :(得分:0)
例如,您可以使用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);
}
private static final String[] COUNTRIES = new String[] {
"Belgium", "France", "Italy", "Germany", "Spain"
};
答案 1 :(得分:0)
好,那么您可以使用Realm之类的数据库并将数据存储到DB中。然后在EditText的addTextChangedListener中获取数据。
edtFolderName.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
RealmResults <ObjectClass> results = realm.where(ObjectClass.class)
.like("name",s.toString+"*") // feild name
.findAll();
//You can display this values inside your spinner
}
@Override
public void afterTextChanged(Editable s) {
}
});