zoukankan      html  css  js  c++  java
  • android_MultiAutoCompleteTextView

    package cn.com.sxp;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.ArrayAdapter;
    import android.widget.Button;
    import android.widget.MultiAutoCompleteTextView;

    public class MultiAutoActivity extends Activity {
    private MultiAutoCompleteTextView autoCom = null;;
    private Button btnClear = null;
    private String[] normalString = null;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    normalString = new String[] { "android", "android sxp", "sxp", "sxp wx"};

    autoCom = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView);
    btnClear = (Button) findViewById(R.id.btn);

    // simple_dropdown_item_1line
    // android 简单的一些样式,貌似是自定义的
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
    android.R.layout.simple_dropdown_item_1line, normalString);

    autoCom.setAdapter(adapter);

    // setTokenizer();
    // Sets the Tokenizer 标记生成器 that will be used to determine the relevant range of the text where the user is typing.
    // CommaTokenizer():
    // 这个简易的组件可以用于一些列表中,这些列表包含被逗号以及一个或数个空格断开的项目。
    // 不太理解,这个方法不加的话没法自动完成文本;添加的话又觉得是废话,列表当然以逗号分隔了
    autoCom.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());

    btnClear.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
    // TODO Auto-generated method stub
    autoCom.setText("");
    }

    });
    }
    }

    XML文件如下:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="fill_parent"
    android:orientation
    ="vertical" >

    <TextView
    android:id="@+id/textView"
    android:layout_width
    ="fill_parent"
    android:layout_height
    ="wrap_content"
    android:layout_gravity
    ="center_horizontal"
    android:text
    ="请输入"
    android:textSize
    ="20px" >
    </TextView>

    <MultiAutoCompleteTextView
    android:id="@+id/multiAutoCompleteTextView"
    android:layout_width
    ="260px"
    android:layout_height
    ="wrap_content"
    android:layout_gravity
    ="center_horizontal"
    android:text
    ="" />

    <Button
    android:id="@+id/btn"
    android:layout_width
    ="wrap_content"
    android:layout_height
    ="wrap_content"
    android:layout_gravity
    ="center_horizontal"
    android:text
    ="清除" >
    </Button>

    </LinearLayout>

    运行效果如下



     

  • 相关阅读:
    PyCharm小技巧
    How to install torcs package in Debian
    QT4.8.6静态编译
    Debian初识(选择最佳镜像发布站点加入source.list文件)
    Dev-C++ 小问题锦集
    ubuntu 12.04lts 安装mysql ,并通过QT连接
    win7下安装ubuntu14.04lts 双系统
    cmake打印变量值
    驾车常识:小轿车灯光
    汽车点火开关的功能介绍
  • 原文地址:https://www.cnblogs.com/itblog/p/2322870.html
Copyright © 2011-2022 走看看