Android控件之-AutoComplete-TextView

很多textField里面都有这种自动提示的功能:

当你输入一个字母或者一个汉字时会自动显示一些提示的信息:

package com.ko8e;

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

public class MyActivity extends Activity {
	/** Called when the activity is first created. */
	private static final String[] nContent = { "zhuo", "kobe", "zhuori",
			"kobebryant", "ko8e", "ko8ebryant" };
	private AutoCompleteTextView autoView = null;
	private TextView view = null;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
				android.R.layout.simple_dropdown_item_1line, nContent);
		view = (TextView) findViewById(R.id.view);
		autoView = (AutoCompleteTextView) findViewById(R.id.autoView);
		view.setText(R.string.hello);
		// 将adapter添加到AutoCompleteTextView中
		autoView.setAdapter(adapter);

	}
	/* protected void onCreate(Bundle icicle) {
         super.onCreate(icicle);
         setContentView(R.layout.main);

         ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
                 android.R.layout.simple_dropdown_item_1line, COUNTRIES);
         AutoCompleteTextView textView = (AutoCompleteTextView)
                 findViewById(R.id.autoView);
         textView.setAdapter(adapter);
     }

     private static final String[] COUNTRIES = new String[] {
         "Belgium", "France", "Italy", "Germany", "Spain"
     };*/

}

main.xml:

<?xml version="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"
    >
<TextView  
	android:id="@+id/view"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    />
 <AutoCompleteTextView
 	android:id="@+id/autoView"
 	android:layout_width="fill_parent"
 	android:layout_height="wrap_content"
 	/>
</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值