【问题标题】:How to make a text field to enter countries' name by auto Complete text field [closed]如何通过自动完成文本字段创建文本字段以输入国家/地区名称[关闭]
【发布时间】:2013-11-10 23:09:02
【问题描述】:

我想要一个文本字段,让用户输入国家/地区名称,并在输入名称时自动提供选项。类似于 Google 搜索,它根据输入的字母进行预测。但就我而言,它应该显示国家名称。我知道我必须使用 AutoCompleteTextField 但不知道如何添加国家名称。

有什么想法吗?

【问题讨论】:

标签: java android autocomplete android-widget uitextfield


【解决方案1】:

在countrys.xml文件res/values/country.xml上创建一个集合:

<resources>
<string-array name="country_items">
    <item>USA</item>
    <item>UK</item>
    <item>Japan</item>
</string-array>
</resources>

在您的活动中...

String[] Country = this.getResources().getStringArray(R.array.country_items);

【讨论】:

    【解决方案2】:

    你可能想看看这个帖子:

    How to set Adapter to Auto Complete Text view?

    只需将月份列表替换为您的国家/地区列表即可。

    【讨论】:

    • 感谢您的帖子。这似乎是一个很好的解决方案,但正如你所知,国家列表真的很长,差不多 200 个。是否可以将所有名称放在一个 txt 文件中然后附加?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-08
    • 2010-10-15
    • 2014-09-30
    • 2011-04-29
    • 2013-03-23
    相关资源
    最近更新 更多