AutoCompleteTextViewActivity自动完成文本框

xml文件

·1..main.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" >

  <AutoCompleteTextView
      android:id="@+id/auto"
      android:layout_width="fill_parent"
    android:layout_height="wrap_content"
     android:layout_marginLeft="10dp"
    />

</LinearLayout>

2.在res下layout下新建一个list_item的xml文件注:是Textview

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/tv11"
      android:layout_width="fill_parent"
    android:layout_height="fill_parent"
      android:padding="10dp"
      android:textSize="16sp"
      android:textColor="#000" >
</TextView>

 注:不能输入中文,可以长按输入框改输入法便可以

主窗体

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
 
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
 
import android.widget.TextView;
 

public class AutoCompleteTextViewActivity extends Activity {
    /** Called when the activity is first created. */
 TextView tv1;TextView tv11;
 AutoCompleteTextView autocompletetextview ;
 ArrayList<String> list;
 
// private String ss;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        autocompletetextview=(AutoCompleteTextView)this.findViewById(R.id.auto);
        list=new ArrayList<String>();
        list.add("cys");
        list.add("生哥");
        list.add("english");
       
        ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,R.layout.list_item,list);
        autocompletetextview.setAdapter(adapter);

}}

 

 

阅读更多
换一批

没有更多推荐了,返回首页