如何使自动完成文本视图仅接受已经写的短语

发布于 2025-01-25 08:51:49 字数 92 浏览 4 评论 0 原文

我已经列出了 Android Studio中的自动完成文本视图,我希望自动完成仅接受此列表中的短语 例如,如果我的阵列包含莎拉,迈克,亚当 我在自动完成的文本视图上写了。

I already made a list of phrases for
autocomplete text view in android studio and i want the autocomplete to accept only phrases in this list
For e.g if my array contain sarah,mike,adam
And i wrote in the autocomplete text view omar .. the autocomplete text view will not accept it ..it will delete it .

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还给你自由 2025-02-01 08:51:49

您可以尝试这样的尝试:

   protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.yourLayout);

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, PHRASES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.yourTextView);
         textView.setAdapter(adapter);
     }

     private static final String[] PHRASES = new String[] {
         "Belgium", "France", "Italy", "Germany", "Spain"
     };

 

还应该看看Android开发人员网站:

you can try something like this:

   protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.yourLayout);

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, PHRASES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.yourTextView);
         textView.setAdapter(adapter);
     }

     private static final String[] PHRASES = new String[] {
         "Belgium", "France", "Italy", "Germany", "Spain"
     };

 

Also you should take a look of the android developer site: AutoCompleteTextView

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文