标签:cuc case aof ado who slax dfs gety work
1.使用方法
布局文件
<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" 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=".MainActivity" > <AutoCompleteTextView android:id="@+id/autoCompleteTextView1" android:completionThreshold="3" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="请输入关键词" > <requestFocus /> </AutoCompleteTextView> </LinearLayout>
MainActivity.java
package com.example.mooc; import android.R.anim; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.ArrayAdapter; import android.widget.AutoCompleteTextView; import android.widget.Button; import android.widget.ImageButton; import android.widget.Toast; public class MainActivity extends Activity { private Button login_button; private ImageButton img_button; private AutoCompleteTextView autoCompleteTextView1; private String res[] = {"beijing1","beijing2","beijing3"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 将布局文件引入到Activity setContentView(R.layout.auto_complete); /** * 1.初始化一个对象 * 2.需要一个适配器 * 3.初始化数据源 * 4.设置适配器 */ autoCompleteTextView1 = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView1); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, res); autoCompleteTextView1.setAdapter(adapter); }
效果:
-----------------------------MultiAutoCompleteTextView------------------------------
布局文件:
<MultiAutoCompleteTextView android:id="@+id/multiAutoCompleteTextView1" android:completionThreshold="3" android:layout_width="match_parent" android:layout_height="wrap_content" android:ems="10" android:hint="请输入你的收件人" />
Java代码:
private String res[] = { "beijing1", "beijing2", "beijing3" }; /** * 1.初始化一个对象 2.需要一个适配器 3.初始化数据源 4.设置适配器 5.设置分隔符 */ mutiple = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1); mutiple.setAdapter(adapter); // 设置分隔符 mutiple.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
效果:
Android控件——AutoCompleteTextView与MultiAutoCompleteTextView(实现自动匹配输入的内容)
标签:cuc case aof ado who slax dfs gety work
原文地址:http://www.cnblogs.com/qlqwjy/p/7460801.html