以编程方式选择Android字词建议

时间:2011-01-10 12:37:12

标签: android

如何从Android中以编程方式选择Android Word建议?

2 个答案:

答案 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"
 };

} 或使用此链接: How to include suggestions in Android Keyboard

答案 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) {

 }
});