【问题标题】:picking Android word suggestions programmatically以编程方式选择 Android 单词建议
【发布时间】:2019-01-15 14:05:00
【问题描述】:

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

【问题讨论】:

  • 你想说你想实现自动完成功能吗?
  • 不,亲爱的,我不想实现功能,我只想以编程方式选择已经存储的单词。

标签: android


【解决方案1】:

您可以使用 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

【讨论】:

  • 请分享完整的例子......我需要代码..
【解决方案2】:

好的,那么您可以使用 Realm 之类的数据库并将数据存储到数据库中。然后在 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) {

 }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-05-14
    • 2013-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多