1、视图
1 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 2 xmlns:tools="http://schemas.android.com/tools" 3 android:layout_width="match_parent" 4 android:layout_height="match_parent" 5 tools:context=".MainActivity" > 6 7 <AutoCompleteTextView 8 android:layout_width="fill_parent" 9 android:layout_height="wrap_content" 10 android:id="@+id/name" 11 android:completionThreshold="1" 12 /> 13 14 </RelativeLayout>
2、java代码
1 package com.example.myautocompletetextview; 2 3 import android.os.Bundle; 4 import android.app.Activity; 5 import android.view.Menu; 6 import android.widget.ArrayAdapter; 7 import android.widget.AutoCompleteTextView; 8 9 public class MainActivity extends Activity { 10 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 super.onCreate(savedInstanceState); 14 setContentView(R.layout.activity_main); 15 16 AutoCompleteTextView nameText = (AutoCompleteTextView) findViewById(R.id.name); 17 String[] names = {"老张","老王","老洪","老钱","芳芳"}; 18 ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,names); 19 nameText.setAdapter(adapter); 20 } 21 22 23 24 }
时间: 2024-12-29 12:02:11