android 自动匹配文本 AutoCompleteTextView /MultiAutoCompleteTextView

AutoCompleteTextView:每个文本框只能匹配一次

MultiAutoCompleteTextView:能以分隔符为分割点多次匹配

 

 

 1         //AutoComplete 的 XML示例
 2      <AutoCompleteTextView
 3          android:completionThreshold="3"      //输入数达到3时开始显示提示
 4          android:id="@+id/autoCompleteTextView1"
 5          android:layout_width="match_parent"
 6          android:layout_height="wrap_content"
 7          android:layout_alignParentLeft="true"
 8          android:layout_alignParentTop="true"
 9          android:ems="10"
10          android:hint="请输入关键字" >
11      </AutoCompleteTextView>    
 1         //AutoComplete java示例
 2 
 3 public class MainActivity extends Activity {
 4     private AutoCompleteTextView acTextView;
 5     private String[] res = {"beijing1","beijing2","beijing3",          //提示资源
 6                             "shanghai1","shanghai2"};
 7     
 8     @Override
 9     protected void onCreate(Bundle savedInstanceState) {
10         super.onCreate(savedInstanceState);
11         setContentView(R.layout.fragment_main);
12         /**
13          * 1、初始化控件
14          * 2、需要一个适配器,ArrayAdapter<String>
15          * 3、初始化数据源---匹配文本框输入的内容
16          * 4、将adapter与AutoCompleteTextView绑定
17          */
18         
19         acTextView = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);
20         ArrayAdapter<String> adapter = new ArrayAdapter<>(this, 
21                 android.R.layout.simple_list_item_1, res);    //3个参数:上下文,布局,资源
22         acTextView.setAdapter(adapter);    //绑定
23     }
24 }

 

android 自动匹配文本 AutoCompleteTextView /MultiAutoCompleteTextView

 

 

 

 

 1          //MultiAutoCompleteTextView XML示例
 2 
 3     <MultiAutoCompleteTextView
 4         android:id="@+id/multiAutoCompleteTextView1"
 5         android:layout_width="match_parent"
 6         android:layout_height="wrap_content"
 7         android:layout_alignParentLeft="true"
 8         android:layout_alignParentTop="true"
 9         android:ems="10"
10         android:hint="请输入关键字" />

 

 

 1        //MultiAutoCompleteTextView  的java示例
 2 
 3 public class MainActivity extends Activity {
 4     private MultiAutoCompleteTextView macTextView;
 5     private String[] res = {"beijing1","beijing2","beijing3",
 6                             "shanghai1","shanghai2"};
 7     
 8     @Override
 9     protected void onCreate(Bundle savedInstanceState) {
10         super.onCreate(savedInstanceState);
11         setContentView(R.layout.fragment_main);
12         /**
13          * 1、初始化控件
14          * 2、需要一个适配器,ArrayAdapter<String>
15          * 3、初始化数据源---匹配文本框输入的内容
16          * 4、将adapter与AutoCompleteTextView绑定
17          * 5、设置分割符
18          */
19         
20         macTextView = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
21         ArrayAdapter<String> adapter = new ArrayAdapter<>(this, 
22                 android.R.layout.simple_list_item_1, res);
23         macTextView.setAdapter(adapter);
24         //设置以 逗号为分割符
25         macTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer()); 
26                                                     //在系统自定义中分隔符只有 逗号,其他需要自设
27     }
28 }

 

 android 自动匹配文本 AutoCompleteTextView /MultiAutoCompleteTextView

 

 

                                                                                                                2014-08-16

 

android 自动匹配文本 AutoCompleteTextView /MultiAutoCompleteTextView,布布扣,bubuko.com

android 自动匹配文本 AutoCompleteTextView /MultiAutoCompleteTextView

上一篇:nyist oj 289 苹果 (动态规划——背包问题)


下一篇:IOS多线程_NSThread和NSInvocationOperation