Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框相关的知识,希望对你有一定的参考价值。
Activity:
1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 android:orientation="vertical" 6 tools:context="com.example.top5_2.MainActivity" > 7 8 <EditText 9 android:layout_width="fill_parent" 10 android:layout_height="wrap_content" 11 android:paddingLeft="5dp" 12 android:background="#FFA500" 13 android:textSize="16sp" 14 android:drawableLeft="@drawable/ic_launcher" 15 android:text="多匹配自动补全演示" /> 16 <MultiAutoCompleteTextView 17 android:id="@+id/ed" 18 android:layout_width="fill_parent" 19 android:layout_height="wrap_content" 20 style="@android:attr/textViewStyle" 21 android:hint="请输入单词" 22 android:layout_marginTop="10dp" 23 android:completionThreshold="2" 24 /> 25 </LinearLayout>
JAVA:
1 public class MainActivity extends Activity { 2 private MultiAutoCompleteTextView mct; 3 private static final String[] words={"abc","acd","ade"}; 4 @Override 5 protected void onCreate(Bundle savedInstanceState) { 6 super.onCreate(savedInstanceState); 7 setContentView(R.layout.activity_main); 8 9 mct=(MultiAutoCompleteTextView) findViewById(R.id.ed); 10 ArrayAdapter<String> aa=new ArrayAdapter<String>(this, 11 android.R.layout.simple_dropdown_item_1line,words); 12 mct.setAdapter(aa); 13 mct.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 14 } 15 public boolean onCreateOptionsMenu(Menu menu){ 16 getMenuInflater().inflate(R.menu.main, menu); 17 return true; 18 }
运行效果:
以上是关于Android基础TOP5_2:MultiAutoCompleteTextView多文本自动补全文本框的主要内容,如果未能解决你的问题,请参考以下文章
Android基础TOP5_4:点击按钮更换样式,设置透明度