• MultiAutoCompleteTextView


     

    Activity_mian.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: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.autocompletetextviewdemo.MainActivity" 

        android:orientation="vertical">

    <MultiAutoCompleteTextView

            android:id="@+id/multiAutoCompleteTextView1"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:hint="请输入要搜索的关键字"

            android:completionThreshold="2"/>

     

    </LinearLayout>

    MainActivity.java

    package com.example.autocompletetextviewdemo;

     

    import android.os.Bundle;

    import android.support.v7.app.ActionBarActivity;

    import android.widget.ArrayAdapter;

    import android.widget.MultiAutoCompleteTextView;

     

    public class MainActivity extends ActionBarActivity {

    //声明控件

    // AutoCompleteTextView actv;

    MultiAutoCompleteTextView mactv;

    //初始化数据源,去匹配文本框中输入的关键字

    String[] str={"beijing","beijing1","beijing2","nanjing","yanjing","yantai","nanguo"};

    @Override

    protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    //初始化控件

    // actv=(AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1);

    mactv=(MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);

    //需要一个适配器

    ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, str);

    //将适配器与控件绑定

    // actv.setAdapter(adapter);

    mactv.setAdapter(adapter);

    //设置分隔符,以逗号为分隔符

    mactv.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer() );

     

    }

    }

     

     

     

  • 相关阅读:
    Ubuntu1804 安装 cuda 、cudnn、TensorRT
    sudo apt install nvinfer*
    PyTorch for Jetson Nano
    Jetson Nano安装 Jupyter lab
    docker容器登录,退出等操作命令
    pyenv和pipenv简单使用
    pyenv使用国内镜像安装指定的Python版本
    python写入csv文件的几种方法总结
    Python 能做什么?
    极验滑块验证的使用
  • 原文地址:https://www.cnblogs.com/cn-chy-com/p/7928457.html
Copyright © 2020-2023  润新知