zoukankan      html  css  js  c++  java
  • 自动文本提示控件

    public class MainActivity extends Activity {

     private AutoCompleteTextView sName;

     private MultiAutoCompleteTextView mName;

     @Override

     protected void onCreate(Bundle savedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);

      // sName = (AutoCompleteTextView) this.findViewById(R.id.s_name);

      mName = (MultiAutoCompleteTextView) this.findViewById(R.id.m_name);

      String[] objects = new String[] { "老张", "老陈", "老谢", "老郑", "老鲁", "老黄",

        "老林" };

      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,

        android.R.layout.simple_dropdown_item_1line, objects);

      // this.sName.setAdapter(adapter);

      this.mName.setAdapter(adapter);

      this.mName.setTokenizer(new Tokenizer() {

       @Override

       public CharSequence terminateToken(CharSequence text) {

        System.out.println("terminateToken......");

        System.out.println(text);

        return null;

       }

       @Override

       public int findTokenStart(CharSequence text, int cursor) {

        System.out.println("findTokenStart.....");

        System.out.println(text);

        System.out.println(cursor);

        return 0;

       }

       @Override

       public int findTokenEnd(CharSequence text, int cursor) {

        System.out.println("findTokenEnd.......");

        System.out.println(text);

        System.out.println(cursor);

        return 0;

       }

      });

     }

    }

    <RelativeLayout 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"

        tools:context=".MainActivity" >

    <!--

        <AutoCompleteTextView

            android:id="@+id/s_name"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:completionThreshold="1" />

     -->

        <MultiAutoCompleteTextView

            android:id="@+id/m_name"

            android:layout_width="match_parent"

            android:layout_height="wrap_content"

            android:completionThreshold="1" />

    </RelativeLayout>

  • 相关阅读:
    C++实现base64编解码
    使用matplotlib绘制3D函数图像
    C++分治策略实现快速排序
    C++分治策略实现二分搜索
    C++生成随机数
    eBay 表结构
    mysql 流程函数
    无限极分类
    PHP 导出 Excell
    js
  • 原文地址:https://www.cnblogs.com/freenovo/p/4469807.html
Copyright © 2011-2022 走看看