AutoCompleteTextView自动填充邮箱后缀
来源:互联网 发布:plc三种编程语言 编辑:程序博客网 时间:2024/05/01 13:57
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="vertical" >
- <AutoCompleteTextView
- android:id="@+id/edit"
- android:layout_width="230dip"
- android:layout_height="wrap_content"
- android:textSize="20sp"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="20dip" />
- </LinearLayout>
程序代码如下:
- package com.android.system.AutoComplete;
- import java.util.ArrayList;
- import java.util.List;
- import android.app.Activity;
- import android.content.Context;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.AutoCompleteTextView;
- import android.widget.BaseAdapter;
- import android.widget.Filter;
- import android.widget.Filterable;
- import android.widget.TextView;
- public class AutoComplete extends Activity {
- AutoCompleteTextView autoview;
- // default city
- String[] stringArray = { "@163.com", "@126.com", "@qq.com", "@sina.com", "@taobao.com" };
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- autoview = (AutoCompleteTextView) findViewById(R.id.edit);
- // adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, stringArray);
- final MyAdatper adapter = new MyAdatper(this);
- autoview.setAdapter(adapter);
- autoview.addTextChangedListener(new TextWatcher() {
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- String input = s.toString();
- adapter.mList.clear();
- if (input.length() > 0) {
- for (int i = 0; i < stringArray.length; ++i) {
- adapter.mList.add(input + stringArray[i]);
- }
- }
- adapter.notifyDataSetChanged();
- autoview.showDropDown();
- }
- });
- // default=2
- autoview.setThreshold(1);
- }
- class MyAdatper extends BaseAdapter implements Filterable {
- List<String> mList;
- private Context mContext;
- private MyFilter mFilter;
- public MyAdatper(Context context) {
- mContext = context;
- mList = new ArrayList<String>();
- }
- @Override
- public int getCount() {
- return mList == null ? 0 : mList.size();
- }
- @Override
- public Object getItem(int position) {
- return mList == null ? null : mList.get(position);
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- if (convertView == null) {
- TextView tv = new TextView(mContext);
- tv.setTextColor(Color.BLACK);
- tv.setTextSize(20);
- convertView = tv;
- }
- TextView txt = (TextView) convertView;
- txt.setText(mList.get(position));
- return txt;
- }
- @Override
- public Filter getFilter() {
- if (mFilter == null) {
- mFilter = new MyFilter();
- }
- return mFilter;
- }
- private class MyFilter extends Filter {
- @Override
- protected FilterResults performFiltering(CharSequence constraint) {
- FilterResults results = new FilterResults();
- if (mList == null) {
- mList = new ArrayList<String>();
- }
- results.values = mList;
- results.count = mList.size();
- return results;
- }
- @Override
- protected void publishResults(CharSequence constraint, FilterResults results) {
- if (results.count > 0) {
- notifyDataSetChanged();
- } else {
- notifyDataSetInvalidated();
- }
- }
- }
- }
- }
代码下载地址:http://download.csdn.net/detail/leiming32/4469341
0 0
- AutoCompleteTextView自动填充邮箱后缀
- AutoCompleteTextView实现邮箱自动填充
- 自动填充邮箱后缀
- android 自定义控件之AutoCompleteTextView邮箱后缀自动补全
- AutoCompleteTextView 自动填充文本框
- 仿网易音乐登陆 android 邮箱自动填充 基于AutoCompleteTextView 修改
- 输入内容自动填充: AutoCompleteTextView
- AutoCompleteTextView实现邮件地址自动填充
- 邮箱自动填充js
- Android学习系列之控件 AutoCompleteTextView邮箱后缀自动补全
- Android学习系列之控件 AutoCompleteTextView邮箱后缀自动补全
- android邮箱自动填充功能
- 邮箱下拉自动填充选择
- 邮箱收件人效果(自动填充)
- 类似邮箱自动填充下拉效果
- Android学习笔记之AutoCompleteTextView自动填充功能的案例
- ajax邮箱后缀自动补全
- JS输入用户名自动显示邮箱后缀列表
- 解析List<Map<String,List<String>>>
- java web 从服务器上下载图片资料
- C# 读取webconfig配置文件Appseting key值的方法
- freeswitch常用命令 陆续更新中
- Hibernate进阶之单向一对多关系映射
- AutoCompleteTextView自动填充邮箱后缀
- JSP页面 include用法
- android对话框
- java可执行jar包关联程序数据
- java输出一个数组的所有排列形式(全排序)
- Windows下u-boot-2011.03在Mini2440移植详解(7)
- 南阳47 过河问题(经典贪心)
- c语言写csv
- 做动画步骤,对于使用adt-bundle-windows-x86-20131030的用户