您好,登錄后才能下訂單哦!
這篇文章主要介紹Android自動(dòng)完成文本框的示例分析,文中介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們一定要看完!
Android:自動(dòng)完成文本框
xml文件代碼如下:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <AutoCompleteTextView android:id="@+id/myAutoCompleteTextView" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
java文件代碼如下:
package com.example.sample_5_1; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; public class AutoCompleteActivity extends AppCompatActivity { private static final String[] myStr = new String[]{ "vae","victory","vision","virtue","vital" }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_auto_complete); ArrayAdapter<String> aa = new ArrayAdapter<String>( //創(chuàng)建適配器 this, // Context android.R.layout.simple_dropdown_item_1line, //使用Android自帶的簡(jiǎn)單布局 myStr); //資源數(shù)組 AutoCompleteTextView myAutoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.myAutoCompleteTextView); //得到控件的引用 myAutoCompleteTextView.setAdapter(aa); //設(shè)置適配器 myAutoCompleteTextView.setThreshold(1); //定義需要用戶輸入的字符數(shù) } }
以上是“Android自動(dòng)完成文本框的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對(duì)大家有幫助,更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。