码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-04-08 17:06:45      阅读:189      评论:0      收藏:0      [点我收藏+]

标签:amp   let   option   down   文本   rri   cal   http   context   

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多文本自动补全文本框

标签:amp   let   option   down   文本   rri   cal   http   context   

原文地址:http://www.cnblogs.com/AndroidCSY/p/6682191.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!