autoCompleteTextView

代码实现:

XML布局:

  <?xmlversion="1.0"encoding="utf-8"?>
  
  
  <LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  
  <!--
  AutoCompleteTextView-支持自动完成功能的可编辑文本控件
  -->
  
  
  <AutoCompleteTextView
  
  android:id="@+id/editText"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"/>
  
  </LinearLayout>

JAVA代码:

  packageEOE.android.IC;
  
  importandroid.app.Activity;
  importandroid.os.Bundle;
  importandroid.widget.ArrayAdapter;
  importandroid.widget.AutoCompleteTextView;
  
  publicclass_AutoCompleteTextViewextendsActivity{
  
  @Override
  protectedvoidonCreate(BundlesavedInstanceState){
  super.onCreate(savedInstanceState);
  setContentView(R.layout.autocompletetextview);
  
  setTitle("AutoCompleteTextView");
  
  //实例化适配器,指定显示格式及数据源
  ArrayAdapter<String>adapter=newArrayAdapter<String>(
  this,android.R.layout.simple_list_item_1,ary);
  
  
  AutoCompleteTextViewtextView=(AutoCompleteTextView)findViewById(R.id.editText);
  
  
  //指定自动完成控件的适配器
  textView.setAdapter(adapter);
  }
  
  //自动完成控件的所需数据的数据源
  privateString[]ary=newString[]{
  "abc",
  "abcd",
  "abcde",
  "abcdef",
  "abcdefg",
  "hij",
  "hijk",
  "hijkl",
  "hijklm",
  "hijklmn",
  };
  
  
  
  }

你可能感兴趣的:(autoCompleteTextView)