码迷,mamicode.com
首页 > 其他好文 > 详细

AutoCompleteTextView与MultiAutoCompleteTextView

时间:2016-06-13 13:18:37      阅读:127      评论:0      收藏:0      [点我收藏+]

标签:

XML布局文件

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent" >
 5 
 6     <AutoCompleteTextView
 7         android:id="@+id/autoCompleteTextView1"
 8         android:layout_width="wrap_content"
 9         android:layout_height="wrap_content"
10         android:layout_alignParentLeft="true"
11         android:layout_alignParentTop="true"
12         android:ems="10"
13         android:hint="请输入城市:"
14         android:completionThreshold="2"
15         /><!-- 设置输入几个开始提示 -->
16 
17     <MultiAutoCompleteTextView
18         android:id="@+id/multiAutoCompleteTextView1"
19         android:layout_width="wrap_content"
20         android:layout_height="wrap_content"
21         android:layout_alignParentLeft="true"
22         android:layout_below="@+id/autoCompleteTextView1"
23         android:ems="10"
24         android:hint="请输入收件人:" 
25         android:completionThreshold="2">
26 
27         <requestFocus />
28     </MultiAutoCompleteTextView>
29 
30 </RelativeLayout>

源代码:

 1 import android.app.Activity;
 2 import android.os.Bundle;
 3 import android.view.Menu;
 4 import android.view.MenuItem;
 5 import android.widget.ArrayAdapter;
 6 import android.widget.AutoCompleteTextView;
 7 import android.widget.MultiAutoCompleteTextView;
 8 
 9 public class MainActivity2 extends Activity {
10     private AutoCompleteTextView at;
11     private MultiAutoCompleteTextView mat;
12     @Override
13     protected void onCreate(Bundle savedInstanceState) {
14         super.onCreate(savedInstanceState);
15         setContentView(R.layout.activity_main2);
16         at = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
17         mat = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
18         
19         ArrayAdapter adapter = ArrayAdapter.createFromResource(this,R.array.city_name, android.R.layout.simple_spinner_dropdown_item);
20         at.setAdapter(adapter);
21     
22         mat.setAdapter(adapter);
23         //设置分隔符
24         mat.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
25     
26     }
27 
28     
29 }

 

AutoCompleteTextView与MultiAutoCompleteTextView

标签:

原文地址:http://www.cnblogs.com/fangg/p/5434662.html

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