Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框

男儿欲遂平生志,五经勤向窗前读。这篇文章主要讲述Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框相关的知识,希望能为你提供帮助。
Activity:

1 < LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2xmlns:tools="http://schemas.android.com/tools" 3android:layout_width="match_parent" 4android:layout_height="match_parent" 5android:orientation="vertical" 6tools:context="com.example.top5_2.MainActivity" > 7 8< EditText 9android:layout_width="fill_parent" 10android:layout_height="wrap_content" 11android:paddingLeft="5dp" 12android:background="#FFA500" 13android:textSize="16sp" 14android:drawableLeft="@drawable/ic_launcher" 15android:text="多匹配自动补全演示" /> 16< MultiAutoCompleteTextView 17android:id="@+id/ed" 18android:layout_width="fill_parent" 19android:layout_height="wrap_content" 20style="@android:attr/textViewStyle" 21android:hint="请输入单词" 22android:layout_marginTop="10dp" 23android:completionThreshold="2" 24/> 25 < /LinearLayout>

java:
1 public class MainActivity extends Activity { 2private MultiAutoCompleteTextView mct; 3private static final String[] words={"abc","acd","ade"}; 4@Override 5protected void onCreate(Bundle savedInstanceState) { 6super.onCreate(savedInstanceState); 7setContentView(R.layout.activity_main); 8 9mct=(MultiAutoCompleteTextView) findViewById(R.id.ed); 10ArrayAdapter< String> aa=new ArrayAdapter< String> (this, 11android.R.layout.simple_dropdown_item_1line,words); 12mct.setAdapter(aa); 13mct.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 14} 15public boolean onCreateOptionsMenu(Menu menu){ 16getMenuInflater().inflate(R.menu.main, menu); 17return true; 18}

运行效果:
Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框

文章图片

【Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框】 

    推荐阅读