Android基础--AutoCompleteTextView控件

来源:互联网 发布:南京行知中学高中部 编辑:程序博客网 时间:2024/05/16 18:44

一)布局文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:orientation="vertical"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    tools:context=".MyActivity" >    <AutoCompleteTextView         android:id="@+id/cctj.sfz"        android:layout_width="120dip"        android:layout_height="38dip"        android:layout_margin="5dip"        />    </LinearLayout>

二)Activity.java

package com.howell.sample6_9;import android.app.Activity;import android.os.Bundle;import android.widget.ArrayAdapter;import android.widget.AutoCompleteTextView;public class MyActivity extends Activity {private String[] strs = new String[]{"fab", "faber", "fable","table", "tableland", "tablet","汉语", "汉语拼音", "汉字", "河北", "河北省", "河南", "河南省",};@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, strs);AutoCompleteTextView textView = (AutoCompleteTextView)findViewById(R.id.cctj_sfz);textView.setThreshold(1);textView.setDropDownHeight(270);textView.setAdapter(adapter);}}


原创粉丝点击