【Android】自动提示匹配之AutoCompleteTextView

public class

AutoCompleteTextView

extends EditText
implements Filter.FilterListener
java.lang.Object
android.view.View
android.widget.TextView
android.widget.EditText
android.widget.AutoCompleteTextView
Known Direct Subclasses

More Information

Note that using a hard-coded string array is not a recommended design practice because your application code should focus on behavior, not content. Application content such as strings should be externalized from the code in order to make modifications to the content easier and facilitate localization of the content. The hard-coded strings are used in this tutorial only to make it simple and focus on theAutoCompleteTextViewwidget. Instead, your application should declare such string arrays in an XML file. This can be done with a<string-array<resource in your projectres/values/strings.xmlfile. For example:

这里讲hard-coded不利于国际化,我们做的AP应该focus在behavior上而不是content.所以建议把上面的String-array放在String.xml文件中,例如:
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="countries_array"> <item>Bahrain</item> <item>Bangladesh</item> <item>Barbados</item> <item>Belarus</item> <item>Belgium</item> <item>Belize</item> <item>Benin</item> </string-array> </resources>

To use these resource strings for theArrayAdapter, replace the originalArrayAdapterconstructor line with the following:
String[] countries = getResources().getStringArray(R.array.countries_array); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, countries);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值