【Android】自動提示匹配之AutoCompleteTextView

iteye_20954發表於2011-12-26
public class

AutoCompleteTextView

extendsEditText
implementsFilter.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);



相關文章