Android自动补全提示
public class AutoCompleteTextViewActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.autocomplete); setTitle("AutoCompleteTextView_Activity"); ArrayAdapter<String> adapter = new ArrayAdapter<String>( this, android.R.layout.simple_dropdown_item_1line, COUNTRIES);//第3个参数为提供数据的数组名 AutoCompleteTextView autotextView = (AutoCompleteTextView) findViewById(R.id.auto_complete); autotextView.setAdapter(adapter);//将adapter适配器添加到auto..对象中 autotextView.setThreshold(1);//设置输入几个字母开始关联,默认是2 } static final String[] COUNTRIES = new String[] { //设置数据源 "China" ,"Russia", "Germany","Ukraine", "Belarus", "USA" ,"China1" ,"China12", "Germany1", "Russia2", "Belarus1", "USA1" }; }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="wrap_content"> <AutoCompleteTextView android:id="@+id/auto_complete" android:layout_width="fill_parent" android:layout_height="wrap_content"/> </LinearLayout>
<?xml version="1.0" encoding="utf-8"?> <resources> <string-array name="countries_array"> <item>China</item> <item>China1</item> <item>China12</item> </string-array> </resources>
String[] COUNTRIES = getResources().getStringArray(R.array.countries_array);
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。