欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

 更新時(shí)間:2017年01月03日 10:55:29   作者:Joanna.Yan  
本文主要介紹了Android自動(dòng)補(bǔ)全提示輸入AutoCompleteTextView、 MultiAutoCompleteTextView,具有一定的參考作用,下面跟著小編一起來(lái)看下吧

以在搜索框搜索時(shí),自動(dòng)補(bǔ)全為例:

其中還涉及到一個(gè)詞,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);
  // 適配器
  // 第三個(gè)參數(shù)是數(shù)據(jù)源
  // 第二個(gè)參數(shù)是樣式資源的id
  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
  android.R.layout.simple_expandable_list_item_1, names);
  // =============只能選擇單個(gè)的自動(dòng)補(bǔ)全=====================
  actv.setAdapter(adapter);
  // =============可選擇多個(gè)的自動(dòng)補(bǔ)全=====================
  // Tokenizer分詞器,分解器
  // MultiAutoCompleteTextView.CommaTokenizer();這個(gè)簡(jiǎn)易的分解器可用于對(duì)由逗號(hào)和若干空格分割的列表進(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>
 <!--定義一個(gè)數(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="只可選擇單個(gè)"
  />
 <!--AutoCompleteTextView 自動(dòng)補(bǔ)全,只能選擇一個(gè)值 
  android:completionThreshold="1" 輸入第一個(gè)字后自動(dòng)補(bǔ)全 -->
 <AutoCompleteTextView
  android:id="@+id/actv"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="請(qǐng)輸入搜索的名字"
  android:completionThreshold="1"
  />
 <TextView 
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="可選擇多個(gè)"
  />
 <!--MultiAutoCompleteTextView 可以選擇多個(gè)值 -->
 <MultiAutoCompleteTextView 
  android:id="@+id/mactv"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:hint="請(qǐng)輸入搜索的名字"
  android:completionThreshold="1"
  />
</LinearLayout>

以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,同時(shí)也希望多多支持腳本之家!

相關(guān)文章

  • Android自定義桌面功能代碼實(shí)現(xiàn)

    Android自定義桌面功能代碼實(shí)現(xiàn)

    android自定義桌面其實(shí)很簡(jiǎn)單,看一個(gè)例子就明白了
    2013-11-11
  • Android自定義控件屬性詳細(xì)介紹

    Android自定義控件屬性詳細(xì)介紹

    這篇文章主要介紹了Android自定義控件屬性詳細(xì)介紹的相關(guān)資料,需要的朋友可以參考下
    2017-05-05
  • 圖文詳解Android Studio搭建Android集成開(kāi)發(fā)環(huán)境的過(guò)程

    圖文詳解Android Studio搭建Android集成開(kāi)發(fā)環(huán)境的過(guò)程

    這篇文章主要以圖文的方式詳細(xì)介紹了Android Studio搭建Android集成開(kāi)發(fā)環(huán)境的過(guò)程,文中安裝步驟介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2015-12-12
  • Android自定義View之繪制圓形頭像功能

    Android自定義View之繪制圓形頭像功能

    這篇文章主要介紹了Android自定義View之繪制圓形頭像功能,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2019-09-09
  • Android入門之在子線程中調(diào)用Handler詳解

    Android入門之在子線程中調(diào)用Handler詳解

    這篇文章主要為大家詳細(xì)介紹了Android如何在子線程中調(diào)用Handler,文中的示例代碼講解詳細(xì),有需要的朋友可以借鑒參考下,希望能夠?qū)Υ蠹矣兴鶐椭?/div> 2022-12-12
  • OpenGL Shader實(shí)現(xiàn)光照發(fā)光體特效

    OpenGL Shader實(shí)現(xiàn)光照發(fā)光體特效

    這篇文章主要介紹了如何通過(guò)OpenGL Shader實(shí)現(xiàn)光照發(fā)光體特效,不同于陰影遮蓋,它是利用圓形繪制向內(nèi)部。感興趣的小伙伴可以了解一下
    2022-02-02
  • Android簡(jiǎn)易圖片瀏覽器的實(shí)現(xiàn)

    Android簡(jiǎn)易圖片瀏覽器的實(shí)現(xiàn)

    最近做了一個(gè)圖片瀏覽小程序,本文主要介紹了Android簡(jiǎn)易圖片瀏覽器的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-03-03
  • Android實(shí)現(xiàn)橫向滑動(dòng)卡片效果

    Android實(shí)現(xiàn)橫向滑動(dòng)卡片效果

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)橫向滑動(dòng)卡片效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • Android創(chuàng)建懸浮窗的完整步驟

    Android創(chuàng)建懸浮窗的完整步驟

    這篇文章主要給大家介紹了關(guān)于Android創(chuàng)建懸浮窗的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05
  • Android?studio?利用共享存儲(chǔ)進(jìn)行用戶的注冊(cè)和登錄驗(yàn)證功能

    Android?studio?利用共享存儲(chǔ)進(jìn)行用戶的注冊(cè)和登錄驗(yàn)證功能

    這篇文章主要介紹了Android?studio?利用共享存儲(chǔ)進(jìn)行用戶的注冊(cè)和登錄驗(yàn)證功能,包括注冊(cè)頁(yè)面布局及登錄頁(yè)面功能,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下
    2021-12-12

最新評(píng)論