Android AutoCompleteTextView 示例含代碼

    Android AutoCompleteTextView 示例

    Android AutoCompleteTextView 根據保留的單詞進行字詞補全,因此無需編寫單詞的所有字符。愛掏網 - it200.com

    Android AutoCompleteTextView是可編輯的文本字段,它在下拉菜單中顯示建議列表,用戶可以僅選擇一個建議或值。愛掏網 - it200.com

    Android AutoCompleteTextView是EditText類的子類。愛掏網 - it200.com而MultiAutoCompleteTextView是AutoCompleteTextView類的子類。愛掏網 - it200.com

    在此示例中,我們將編程語言顯示在自動完成文本視圖中。愛掏網 - it200.com所有的編程語言都存儲在字符串數組中。愛掏網 - it200.com我們使用 ArrayAdapter 類來顯示數組內容。愛掏網 - it200.com

    讓我們看看Android中autocompletetextview的簡單示例。愛掏網 - it200.com

    activity_main.xml

    從面板中拖動AutoCompleteTextView和TextView,現在activity_main.xml文件將會是這樣的:

    <?xml version="1.0" encoding="utf-8"?>  
    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"  
        xmlns:app="http://schemas.android.com/apk/res-auto"  
        xmlns:tools="http://schemas.android.com/tools"  
        android:layout_width="match_parent"  
        android:layout_height="match_parent"  
        tools:context="example.javatpoint.com.autocompletetextview.MainActivity">  
    
        <TextView  
            android:layout_width="wrap_content"  
            android:layout_height="wrap_content"  
            android:text="What is your favourite programming language?"  
            app:layout_constraintBottom_toBottomOf="parent"  
            app:layout_constraintLeft_toLeftOf="parent"  
            app:layout_constraintRight_toRightOf="parent"  
            app:layout_constraintTop_toTopOf="parent"  
            app:layout_constraintVertical_bias="0.032" />  
    
        <AutoCompleteTextView  
            android:id="@+id/autoCompleteTextView"  
            android:layout_width="200dp"  
            android:layout_height="wrap_content"  
            android:layout_marginLeft="92dp"  
            android:layout_marginTop="144dp"  
            android:text=""  
            app:layout_constraintStart_toStartOf="parent"  
            app:layout_constraintTop_toTopOf="parent" />  
    
    </android.support.constraint.ConstraintLayout>  
    

    Activity類

    讓我們來編寫AutoCompleteTextView的代碼。愛掏網 - it200.com

    package example.javatpoint.com.autocompletetextview;
    
    import android.graphics.Color;
    import android.support.v7.app.AppCompatActivity;
    import android.os.Bundle;
    import android.widget.ArrayAdapter;
    import android.widget.AutoCompleteTextView;
    
    public class MainActivity extends AppCompatActivity {
        String[] language ={"C","C++","Java",".NET","iPhone","Android","ASP.NET","PHP"};
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            //Creating the instance of ArrayAdapter containing list of language names
            ArrayAdapter adapter = new ArrayAdapter
                    (this,android.R.layout.select_dialog_item,language);
            //Getting the instance of AutoCompleteTextView
            AutoCompleteTextView actv =  (AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
            actv.setThreshold(1);//will start working from first character
            actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
            actv.setTextColor(Color.RED);
        }
    }
    

    輸出:

    聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。
    發表評論
    更多 網友評論0 條評論)
    暫無評論

    返回頂部

    主站蜘蛛池模板: 精品一区二区三区自拍图片区| 国产精品夜色一区二区三区 | 亚洲一区精彩视频| 国产高清精品一区| 一区二区三区福利| 亚洲国产成人久久一区久久| 91视频一区二区| 无码人妻一区二区三区av| 国产乱码一区二区三区| 国产一区视频在线| 亚洲第一区视频在线观看| 中文字幕在线观看一区二区| 无码人妻少妇色欲AV一区二区| 人妻无码一区二区三区AV| 精品国产AⅤ一区二区三区4区 | 乱码精品一区二区三区| 精品国产日产一区二区三区| 国产在线视频一区| 亚洲国产成人久久综合一区| 亚洲熟妇av一区二区三区漫画| 人妻久久久一区二区三区| 久久亚洲国产精品一区二区| 亚洲日韩精品一区二区三区无码| 国产精品亚洲高清一区二区| 精品不卡一区中文字幕| 国内偷窥一区二区三区视频| 精品久久久久中文字幕一区| 狠狠色婷婷久久一区二区三区| 中文字幕一区在线观看| 中日av乱码一区二区三区乱码| 狠狠色成人一区二区三区| 国产成人一区二区三区在线观看| 国产Av一区二区精品久久| 国产成人午夜精品一区二区三区| 欧洲精品免费一区二区三区| 黑人大战亚洲人精品一区| 国产精品毛片一区二区三区 | 国产aⅴ精品一区二区三区久久| 波多野结衣精品一区二区三区| 国产成人av一区二区三区在线| 亚洲人AV永久一区二区三区久久|