Android自動補全提示-創(chuàng)新互聯(lián)

自動補全提示最主要的是使用AutoCompleteTextView控件,繼而從與控件關聯(lián)的ArrayAdapter提供的字符串集合得到提示。

公司專注于為企業(yè)提供成都做網(wǎng)站、網(wǎng)站制作、微信公眾號開發(fā)、成都商城網(wǎng)站開發(fā),微信平臺小程序開發(fā),軟件定制網(wǎng)站制作等一站式互聯(lián)網(wǎng)企業(yè)服務。憑借多年豐富的經(jīng)驗,我們會仔細了解各客戶的需求而做出多方面的分析、設計、整合,為客戶設計出具風格及創(chuàng)意性的商業(yè)解決方案,創(chuàng)新互聯(lián)建站更提供一系列網(wǎng)站制作和網(wǎng)站推廣的服務。

  先上圖

Android自動補全提示

AutoCompleteTextViewActivity.java代碼如下:

public class AutoCompleteTextViewActivity extends Activity {
	   @Override
	    protected void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.autocomplete);
	        setTitle("AutoCompleteTextView_Activity");
	        ArrayAdapter<String> adapter = new ArrayAdapter<String>(
	        	this,
	            android.R.layout.simple_dropdown_item_1line,
                COUNTRIES);//第2個參數(shù)是每個item的顯示樣式,第3個參數(shù)為提供數(shù)據(jù)的數(shù)組名
	        AutoCompleteTextView autotextView = (AutoCompleteTextView) findViewById(R.id.auto_complete);
	        autotextView.setAdapter(adapter);//將adapter適配器添加到auto..對象中
	        autotextView.setThreshold(1);//設置輸入幾個字母開始關聯(lián),默認是2(threshole:入口,門檻,臨界值)
	    }
	static final String[] COUNTRIES = new String[] {    //設置數(shù)據(jù)源
		"China" ,"Russia", "Germany","Ukraine", "Belarus",
		"USA" ,"China1" ,"China12", "Germany1",
		"Russia2", "Belarus1", "USA1" 
	    };
}

layout中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="wrap_content">

   <AutoCompleteTextView android:id="@+id/auto_complete"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>
</LinearLayout>

當然,為了以后修改數(shù)據(jù)源及代碼的方便,建議將數(shù)據(jù)添加到在layout下的strings.xml文件中去

<?xml version="1.0" encoding="utf-8"?>  
<resources>  
    <string-array name="countries_array">  
        <item>China</item>  
        <item>China1</item>  
        <item>China12</item>                 
    </string-array>  
</resources>

再將原先的數(shù)據(jù)源修改為如下即可

String[] COUNTRIES = getResources().getStringArray(R.array.countries_array);

注意:這條語句應寫在new ArrayAdapter語句之前

另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

網(wǎng)站欄目:Android自動補全提示-創(chuàng)新互聯(lián)
分享網(wǎng)址:http://muchs.cn/article40/ijheo.html

成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、建站公司品牌網(wǎng)站制作、定制開發(fā)、網(wǎng)站制作、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設網(wǎng)站維護公司