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     }

运行效果:

 

posted @ 2017-04-08 16:26  AndrioidCSY  阅读(1435)  评论(0编辑  收藏  举报