Android之AutoCompleteTextView

AutoCompleteTextView是用於總動完成輸入文本的組件,用好了是非常方便用戶的。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    
    <AutoCompleteTextView 
        android:id="@+id/auto"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionHint="選中班級"
        android:completionThreshold="1"    //定義了從第幾個字符開始顯示候補列表
        android:dropDownHeight="300dp"/>

</LinearLayout>

對應的Java代碼

AutoCompleteTextView auto = (AutoCompleteTextView) findViewById(R.id.auto);
//使用AutoCompleteTextView要用到適配器
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
	getApplicationContext(), android.R.layout.simple_list_item_1,
				new String[] { "android", "java", ".net" });//自動提示的選項
auto.setAdapter(adapter);




 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章