Android中AutoCompleteTextView與MultiAutoCompleteTextView的用法
本文以實例列舉了Android中AutoCompleteTextView與MultiAutoCompleteTextView的使用方法,具體使用方法如下:
首先看AutoCompleteTextView的使用:
支持基本的自動完成功能,適用在各種搜索功能中,并且可以根據(jù)自己的需求設置他的默認顯示數(shù)據(jù)。
兩個控件都可以很靈活的預置匹配的那些數(shù)據(jù),并且可以設置輸入多少值時開始匹配等等功能。
布局文件很簡單,如下所示:
<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不應該設置為wrap_content,否則下拉提示只能看到第一個提示,后面的內容看不到。
業(yè)務代碼如下:
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的使用:
該控件可支持選擇多個值(在多次輸入的情況下),分別用分隔符分開,并且在每個值選中的時候再次輸入值時會自動去匹配。
可用在發(fā)短信,發(fā)郵件時選擇聯(lián)系人這種類型當中。
使用時需要執(zhí)行設置分隔符方法。
MultiAutoCompleteTextView的使用和AutoCompleteTextView類似,只是需要設置分隔符:
具體的使用方法為在setAdapter()方法后添加:
mTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
- Android實現(xiàn)自動文本框提示功能
- Android自動編輯文本框(AutoCompleteTextView)使用方法詳解
- Android AutoCompleteTextView自動提示文本框實例代碼
- Android自動文本框輸入識別提示功能代碼
- Android中EditText和AutoCompleteTextView設置文字選中顏色方法
- Android AutoCompleteTextView控件使用實例
- 基于Android中的 AutoCompleteTextView實現(xiàn)自動填充
- 實例講解Android中的AutoCompleteTextView自動補全組件
- Android AutoCompleteTextView連接數(shù)據(jù)庫自動提示的方法(附demo源碼下載)
- Android高級組件AutoCompleteTextView自動完成文本框使用詳解
相關文章
Android開發(fā)入門之Notification用法分析
這篇文章主要介紹了Android中Notification用法,較為詳細的分析了Notification的功能、使用步驟與相關注意事項,需要的朋友可以參考下2016-07-07
Android studio 使用Debugger問題(代碼中含有ndk)
這篇文章主要介紹了Android studio 使用Debugger問題(代碼中含有ndk),非常不錯,具有參考借鑒價值,需要的朋友可以參考下2017-11-11
Android編程實現(xiàn)的自定義彈窗(PopupWindow)功能示例
這篇文章主要介紹了Android編程實現(xiàn)的自定義彈窗(PopupWindow)功能,結合簡單實例形式分析了Android自定義彈窗實現(xiàn)方法與相關注意事項,需要的朋友可以參考下2017-03-03
Android studio 3.0 查看手機文件系統(tǒng)的方法(超簡單)
本文給大家分享Android studio更新到3.0版本之后,查看手機文件系統(tǒng)的方法,需要的朋友參考下吧2017-11-11
Android RecyclerView自定義上拉和下拉刷新效果
這篇文章主要為大家詳細介紹了Android RecyclerView自定義上拉和下拉刷新效果,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-02-02

