Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android開發之AutoCompleteTextView控件

Android開發之AutoCompleteTextView控件

編輯:關於Android編程

\

AutoCompleteTextView是一個可編輯的文本,自動顯示與用戶輸入字符串部分匹配和位置匹配的字符串,從中進行選擇。


介紹幾個方法:<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+MS5zZXRBZGFwdGVyKCk8L3A+CjxwPtfUtq/N6rPJzsSxvr/yyejWw8rKxeTG96Osz9TKvsTcxqXF5NfWt/u0rqGjPC9wPgo8cD4yLnNldFRocmVzaG9sZCgpPC9wPgo8cD7K5MjrtuDJ2bj219a3+7rzv6rKvMalxeShozwvcD4KPHA+My5zZXRUaHJlc2hvbGQoKTwvcD4KPHA+ss7K/c6q19a3+7Suo6zTw7unyuTI67XE19a3+77f09DGpcXkz+7KsaOsz9TKvsalxeTP7qOssqLP1Mq+uMPM4cq+0MXPoqGjPC9wPgo8cD40LnNldERyb3BEb3duQmFja2dyb3VuZFJlc291cmNlKCnT63NldERyb3BEb3duQmFja2dyb3VuZERyYXdhYmxlKCk8L3A+CjxwPsno1sPM4cq+v/K1xLGzvrChozwvcD4KPHA+PGJyPgo8L3A+CjxwPjxicj4KPC9wPgo8cD7Qocq1wP2jujwvcD4KPHA+TWFpbkFjdGl2aXR5LmphdmE8YnI+CjwvcD4KPHA+PHByZSBjbGFzcz0="brush:java;">public class MainActivity extends Activity { AutoCompleteTextView autoCompleteTextView; String[] str = { "peach", "Pear", "Banana", "honeydew", "orange", "tangerine" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.myview); ArrayAdapter arrayAdapter = new ArrayAdapter( MainActivity.this, android.R.layout.simple_dropdown_item_1line, str); //出入3個字符後,開始匹配 autoCompleteTextView.setThreshold(3); //提示信息 autoCompleteTextView.setCompletionHint("選擇一項"); //背景 autoCompleteTextView.setDropDownBackgroundResource(R.drawable.blue); // autoCompleteTextView.setDropDownBackgroundDrawable(d) autoCompleteTextView.setAdapter(arrayAdapter); } }
activity_main.xml



    


效果圖:




  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved