国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android 自動補(bǔ)全提示輸入AutoCompleteTextView、 MultiAutoCompleteTextView

2019-12-12 04:09:05
字體:
供稿:網(wǎng)友

以在搜索框搜索時,自動補(bǔ)全為例:

其中還涉及到一個詞,Tokenizer:分詞器,分解器。

上效果圖:

MainActivity.java:

package com.joan.testautocomletetextview;import android.R.array;import android.os.Bundle;import android.app.Activity;import android.content.res.Resources;import android.view.Menu;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;import android.widget.MultiAutoCompleteTextView;import android.widget.MultiAutoCompleteTextView.Tokenizer;public class MainActivity extends Activity { AutoCompleteTextView actv; MultiAutoCompleteTextView mactv; @Override protected void onCreate(Bundle savedInstanceState) {  super.onCreate(savedInstanceState);  setContentView(R.layout.activity_main);  actv = (AutoCompleteTextView) findViewById(R.id.actv);  mactv = (MultiAutoCompleteTextView) findViewById(R.id.mactv);  // 取到Strings.xml中定義的數(shù)組  String[] names = this.getResources().getStringArray(R.array.names);  // 適配器  // 第三個參數(shù)是數(shù)據(jù)源  // 第二個參數(shù)是樣式資源的id  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,  android.R.layout.simple_expandable_list_item_1, names);  // =============只能選擇單個的自動補(bǔ)全=====================  actv.setAdapter(adapter);  // =============可選擇多個的自動補(bǔ)全=====================  // Tokenizer分詞器,分解器  // MultiAutoCompleteTextView.CommaTokenizer();這個簡易的分解器可用于對由逗號和若干空格分割的列表進(jìn)行分解.  Tokenizer t = new MultiAutoCompleteTextView.CommaTokenizer();  mactv.setAdapter(adapter);  mactv.setTokenizer(t); }}

strings.xml:

<?xml version="1.0" encoding="utf-8"?><resources> <string name="app_name">TestAutocompleteTextView</string> <string name="action_settings">Settings</string> <string name="hello_world">Hello world!</string> <!--定義一個數(shù)組 --> <string-array name="names">  <item >zhangyu</item>  <item >zhangxinzhe</item>  <item >zhangxingxing</item>  <item >liudehua</item>  <item >liuyi</item> </string-array></resources>

activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <TextView   android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="只可選擇單個"  /> <!--AutoCompleteTextView 自動補(bǔ)全,只能選擇一個值   android:completionThreshold="1" 輸入第一個字后自動補(bǔ)全 --> <AutoCompleteTextView  android:id="@+id/actv"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:hint="請輸入搜索的名字"  android:completionThreshold="1"  /> <TextView   android:layout_width="wrap_content"  android:layout_height="wrap_content"  android:text="可選擇多個"  /> <!--MultiAutoCompleteTextView 可以選擇多個值 --> <MultiAutoCompleteTextView   android:id="@+id/mactv"  android:layout_width="match_parent"  android:layout_height="wrap_content"  android:hint="請輸入搜索的名字"  android:completionThreshold="1"  /></LinearLayout>

以上就是本文的全部內(nèi)容,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時也希望多多支持武林網(wǎng)!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 西吉县| 大渡口区| 松原市| 双辽市| 海林市| 珲春市| 辽阳市| 江口县| 邳州市| 丹凤县| 宽甸| 舒城县| 华容县| 天全县| 蓝田县| 新平| 喀喇| 临安市| 鄂温| 若羌县| 定陶县| 宜黄县| 镇安县| 栖霞市| 清徐县| 广州市| 奉节县| 锡林郭勒盟| 安泽县| 松江区| 南平市| 吉林省| 阿克苏市| 赣州市| 彰武县| 开封市| 名山县| 安顺市| 临漳县| 尉犁县| 灌阳县|