开发工具:
文件大小: 32kb
下载次数: 0
上传时间: 2012-10-23
详细说明: 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.T extView; 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(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 mList; private Context mContext; private MyFilter mFilter; public MyAdatper(Context context) { mContext = context; mList = new ArrayList(); } @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(); } results.values = mList; results.count = mList.size(); return results; } @Override protected void publishResults(CharSequence constraint, FilterResults results) { if (results.count > 0) { notifyDataSetChanged(); } else { notifyDataSetInvalidated(); } } } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.