AutoCompleteTextView
AutoCompleteTextView 是 EditText 的子類。它是一個自動提示內容的文本框。顧名思義,它可以在當用戶輸入一定的字符時 AutoCompleteTextView 會顯示一個下拉框,讓用戶選擇,選擇後 AutoCompleteTextView 就會自動將內容填入文本框。
選擇後自動填入文本框 —>
AutoCompleteTextView 除了使用 EditText 的屬性之外,還有一些常用的屬性和方法:
android:completionThreshold --> setThreshlod(int) [用戶至少輸入幾個字符纔會顯示提示]
android:completionHint --> setCompletionHint(CharSequence) [下來菜單中的提示標題]
android:popupBackground --> setDrwnBackgroundResource(int) [下拉菜單的背景]
android:dropDownAnchor --> setDownAnchor(int) [下拉菜單的定位錨點組件]
android:dropDownHeight --> setDownHeight(int) [下拉菜單的高度]
android:dropDownWidth --> setDownWidth(int) [下拉菜單的寬度]
android:completionHintView [下拉菜單中提示標題的視圖]
android:dropDownVerticalOffset [下拉菜單與文本框的垂直偏移]
android:dropDownHorizontalOffset [下拉菜單與文本框的水平偏移]
設置一個 Adapter 就可以使用 AutoCompleteTextView 了,Adapter 裏封裝AutoCompleteTextView 的預設提示文本。是不是很簡單~
試一下:
OK!自動完成!