欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android中AutoCompleteTextView與MultiAutoCompleteTextView的用法

 更新時(shí)間:2014年07月21日 17:19:00   投稿:shichen2014  
這篇文章主要介紹了Android中AutoCompleteTextView與MultiAutoCompleteTextView的用法,需要的朋友可以參考下

本文以實(shí)例列舉了Android中AutoCompleteTextView與MultiAutoCompleteTextView的使用方法,具體使用方法如下:

首先看AutoCompleteTextView的使用:

支持基本的自動完成功能,適用在各種搜索功能中,并且可以根據(jù)自己的需求設(shè)置他的默認(rèn)顯示數(shù)據(jù)。
兩個(gè)控件都可以很靈活的預(yù)置匹配的那些數(shù)據(jù),并且可以設(shè)置輸入多少值時(shí)開始匹配等等功能。
布局文件很簡單,如下所示:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical" >
  <AutoCompleteTextView
    android:id="@+id/tv"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
</LinearLayout>

這里需要說明一下layout_width不應(yīng)該設(shè)置為wrap_content,否則下拉提示只能看到第一個(gè)提示,后面的內(nèi)容看不到。
業(yè)務(wù)代碼如下:

protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 mTextView = (AutoCompleteTextView)findViewById(R.id.tv);
 
 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,autoStr);
 mTextView.setAdapter(adapter);
}

MultiAutoCompleteTextView的使用:

該控件可支持選擇多個(gè)值(在多次輸入的情況下),分別用分隔符分開,并且在每個(gè)值選中的時(shí)候再次輸入值時(shí)會自動去匹配。
可用在發(fā)短信,發(fā)郵件時(shí)選擇聯(lián)系人這種類型當(dāng)中。
使用時(shí)需要執(zhí)行設(shè)置分隔符方法。
MultiAutoCompleteTextView的使用和AutoCompleteTextView類似,只是需要設(shè)置分隔符
具體的使用方法為在setAdapter()方法后添加:

mTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

相關(guān)文章

最新評論