androidのautoCompleteTextView
activity
package com.ghg.autoCompleteTextView;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
/**
* , ,
* @author gaohong
*/
public class Day0605_AutoCompleteTextViewActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
initView();
}
private String[] arr=new String[]{"henan","hebei","shanxin","shandong"};
AutoCompleteTextView aTextView;
private void initView() {
// TODO Auto-generated method stub
aTextView=(AutoCompleteTextView) findViewById(R.id.actv);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, arr);
aTextView.setAdapter(adapter);
}
}
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="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="64dp"
android:text=" "
android:textSize="20sp"
/>
<AutoCompleteTextView
android:id="@+id/actv"
android:layout_width="0dp"
android:layout_height="64dp"
android:layout_weight="1.0"
/>
</LinearLayout>