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

Android實現(xiàn)動態(tài)自動匹配輸入內(nèi)容

 更新時間:2018年08月10日 08:36:37   作者:流年若逝  
這篇文章主要為大家詳細(xì)介紹了Android實現(xiàn)動態(tài)自動匹配輸入內(nèi)容,具有一定的參考價值,感興趣的小伙伴們可以參考一下

Android實現(xiàn)動態(tài)自動匹配的控件主要有MultiAutoCompleteTextView和AutoCompleteTextView

MultiAutoCompleteTextView:

可支持選擇多個值(在多次輸入的情況下),分別用分隔符分開,并且在每個值選中的時候再次輸入值時會自動去匹配

可用在發(fā)短信,發(fā)郵件時選擇聯(lián)系人這種類型當(dāng)中,使用時需要執(zhí)行設(shè)置分隔符方法.

AutoCompleteTextView:

支持基本的自動完成功能,適用在各種搜索功能中,并且可以根據(jù)自己的需求設(shè)置他的默認(rèn)顯示數(shù)據(jù)

兩個控件都可以很靈活的預(yù)置匹配的那些數(shù)據(jù),并且可以設(shè)置輸入多少值時開始匹配等等功能

效果圖如下

輸入相應(yīng)的字符就會出現(xiàn)相應(yīng)的提示,具體操作如下

在MainActivity.java中

package com.example.myapplication;
 
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.MultiAutoCompleteTextView;
 
public class MainActivity extends AppCompatActivity {
  //初始化控件
  private AutoCompleteTextView autoCompleteTextView;
  private MultiAutoCompleteTextView multiAutoCompleteTextView;
  //初始化數(shù)據(jù)源
  private String [] res = {"biejing","nangchang","chengdu","shanghai"};
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    /**
     * AutoCompleteTextView的用法
     */
    autoCompleteTextView = (AutoCompleteTextView) findViewById(R.id.auto_textView);
    //創(chuàng)建適配器
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,res);
    //將adapter與autoCompleteTextView綁定
    autoCompleteTextView.setAdapter(adapter);
 
    /**
     * MultiAutoCompleteTextView的用法
     */
    multiAutoCompleteTextView = (MultiAutoCompleteTextView) findViewById(R.id.mauto_textView);
    //將adapter與multiAutoCompleteTextView綁定
    multiAutoCompleteTextView.setAdapter(adapter);
    //設(shè)置以逗號為分隔符結(jié)束的符號
    multiAutoCompleteTextView.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
 
  }
}

在activity_layout.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/activity_main"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  tools:context="com.example.myapplication.MainActivity"
  android:orientation="vertical"
  >
 
  <AutoCompleteTextView
    android:completionThreshold="3"
    android:id="@+id/auto_textView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="請輸入關(guān)鍵字"
    />
  <MultiAutoCompleteTextView
    android:hint="請輸入多個關(guān)鍵字"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/auto_textView"
    android:id="@+id/mauto_textView" />
 
</RelativeLayout>

 以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android仿微信布局的實現(xiàn)示例

    Android仿微信布局的實現(xiàn)示例

    本文主要介紹了Android仿微信布局的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • Android NavigationBar問題處理的方法

    Android NavigationBar問題處理的方法

    本篇文章主要介紹了Android NavigationBar問題處理的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-10-10
  • 簡單仿寫Android控件SlidingMenu的實例代碼

    簡單仿寫Android控件SlidingMenu的實例代碼

    下面小編就為大家分享一篇簡單仿寫Android控件SlidingMenu的實例代碼,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-01-01
  • RecyclerView使用payload實現(xiàn)局部刷新

    RecyclerView使用payload實現(xiàn)局部刷新

    這篇文章主要為大家詳細(xì)介紹了RecyclerView使用payload實現(xiàn)局部刷新,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • 淺析Android文件存儲

    淺析Android文件存儲

    本文詳細(xì)介紹了android的外部存儲和私有存儲。大家在有保存文件的需求的時候,根據(jù)自己的需要,選擇到底是存在哪里比較合適。內(nèi)部存儲相對較小,不介意把一些大文件存在其中。應(yīng)該存在外部存儲會更好。對于可以給其他文件訪問的,可以存在外部存儲的公有文件里面
    2021-06-06
  • 圖解 Kotlin SharedFlow 緩存系統(tǒng)及示例詳解

    圖解 Kotlin SharedFlow 緩存系統(tǒng)及示例詳解

    這篇文章主要為大家介紹了圖解 Kotlin SharedFlow 緩存系統(tǒng)及示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-10-10
  • Kotlin操作符重載實例詳解

    Kotlin操作符重載實例詳解

    Kotlin允許我們?yōu)樽约旱念愋吞峁╊A(yù)定義的一組操作符的實現(xiàn),下面這篇文章主要給大家介紹了關(guān)于Kotlin操作符重載的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2022-04-04
  • Android 組件Gallery和GridView示例講解

    Android 組件Gallery和GridView示例講解

    本文主要講解Android 組件Gallery和GridView,這里詳細(xì)介紹組件Gallery和GridView的知識要點,并附示例代碼和實現(xiàn)效果圖,有興趣的小伙伴可以參考下
    2016-08-08
  • Android仿IOS10圓盤時間選擇器

    Android仿IOS10圓盤時間選擇器

    這篇文章主要為大家詳細(xì)介紹了Android仿IOS10圓盤時間選擇器,自定義圓盤時間選擇器,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2018-07-07
  • Flutter開發(fā)之Shortcuts快捷鍵組件的用法詳解

    Flutter開發(fā)之Shortcuts快捷鍵組件的用法詳解

    在桌面端的開發(fā)中,鍵盤快捷鍵是非常常見而必要的,F(xiàn)lutter?既然可以開發(fā)桌面端應(yīng)用,那必然要提供自定義快捷鍵,所以本文就來和大家講講Shortcuts組件的簡單使用吧
    2023-05-05

最新評論