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>



發佈了30 篇原創文章 · 獲贊 81 · 訪問量 24萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章