Android 之 自动提示功能(AutoCompleteTextView)的使用

  • 内容
  • 评论
  • 相关
package com.gaoxueping.mobile;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;

public class MainActivity extends Activity {
	private static final String[] COUNTRIES = {"gaoxueping", "Gaoxueping", "hellogxp", "Gao", "Gavin"};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line,COUNTRIES);
		AutoCompleteTextView autoComplete = (AutoCompleteTextView) findViewById(R.id.autoComplete);
		autoComplete.setAdapter(adapter);
		autoComplete.setThreshold(1);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}

}

布局文件

<?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/autoComplete" 
  						android:layout_width="fill_parent" 
  						android:layout_height="wrap_content">
  </AutoCompleteTextView>
</LinearLayout>

完整项目文件下载
http://pan.baidu.com/s/1qWPPoeg

评论

0条评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注