ANDROID笔记:AutoCompleteTextView的简单使用
1 package com.example.autotextview; 2 3 import android.app.Activity; 4 import android.os.Bundle; 5 import android.widget.ArrayAdapter; 6 import android.widget.AutoCompleteTextView; 7 8 import com.example.adaptertest.R; 9 10 public class AutoTextActivity extends Activity { 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 // TODO Auto-generated method stub 14 super.onCreate(savedInstanceState); 15 setContentView(R.layout.autoconpletetext); 16 17 AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.autotext); 18 ArrayAdapter<String> adapter = new ArrayAdapter<String>( 19 AutoTextActivity.this, android.R.layout.simple_list_item_1,new String[]{"java","net","android"}); 20 autoCompleteTextView.setAdapter(adapter); 21 22 } 23 }
1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" > 6 7 <AutoCompleteTextView 8 android:id="@+id/autotext" 9 android:layout_width="100dp" 10 android:layout_height="wrap_content" 11 android:completionHint="选中语言" 12 android:completionThreshold="1" 13 android:dropDownHeight="300dp" /> 14 <!-- completionThreshold:输入几个字母时匹配 --> 15 <!-- dropDownHeight: 提示框高度 --> 16 17 </LinearLayout>