- 浏览: 252131 次
- 性别:
- 来自: 内蒙古
文章分类
- 全部博客 (237)
- Android 功能实现 (31)
- sql数据库的学习 (8)
- Android 美化界面 (2)
- Android 优化 (1)
- Ruby on Rails 方面 (45)
- git 方面的学习 (1)
- ruby 编程的琢磨 (13)
- linux下工具软件 (13)
- 操作系统的学习 (40)
- 非技术 (13)
- 网站开发 (18)
- js 学习笔记 (19)
- css学习 (5)
- 回顾总结 (2)
- Delphi 学习 (2)
- C 语言学习笔记 (1)
- 数据结构 (1)
- node js 学习 (6)
- 设计模式 (2)
- mongdb 学习笔记 (0)
- 软件服务 (3)
- osx系统 (4)
- 搜索引擎 (1)
- 测试工具 (1)
- Aliyun (1)
- 前端JS (1)
- python学习 (0)
- iOS系统 (1)
- 分布式锁 (1)
- 开发工具 (0)
- java代码 (2)
- java (1)
最新评论
-
jiguanghover:
写的不错,收藏一下
Ubuntu下RVM, Ruby, rails安装详细 和 卸载 -
maoghj:
回顾总结(二) -
yun2223:
对楼主表示感谢
Android控件开发之Gallery3D效果 -
zw_lovec:
说清楚点吧 亲 加点注释
out of memory -
lzyfn123:
http://www.iteye.com/images/smi ...
ruby-string 字符串的学习
- public class CityAdapter<T> extends BaseAdapter implements Filterable {
- /**
- * Contains the list of objects that represent the data of this ArrayAdapter
.
- * The content of this list is referred to as "the array" in the documentation.
- */
- private List<T> mObjects;
- private List<T> mObjects2;
-
- /**
- * Lock used to modify the content of {@link #mObjects}. Any write operation
- * performed on the array should be synchronized on this lock. This lock is also
- * used by the filter (see {@link #getFilter()} to make a synchronized copy of
- * the original array of data.
- */
- private final Object mLock = new Object();
- /**
- * The resource indicating what views to inflate to display the content of this
- * array adapter.
- */
- private int mResource;
- /**
- * The resource indicating what views to inflate to display the content of this
- * array adapter in a drop down widget.
- */
- private int mDropDownResource;
- /**
- * If the inflated resource is not a TextView, {@link #mFieldId} is used to find
- * a TextView inside the inflated views hierarchy. This field must contain the
- * identifier that matches the one defined in the resource file.
- */
- private int mFieldId = 0;
- /**
- * Indicates whether or not {@link #notifyDataSetChanged()} must be called whenever
- * {@link #mObjects} is modified.
- */
- private boolean mNotifyOnChange = true;
- private Context mContext;
- private ArrayList<T> mOriginalValues;
- private ArrayFilter mFilter;
- private LayoutInflater mInflater;
- /**
- * Constructor
- *
- * @param context The current context.
- * @param textViewResourceId The resource ID for a layout file containing a TextView to use when
- * instantiating views.
- */
- public CityAdapter(Context context, int textViewResourceId) {
- init(context, textViewResourceId, 0, new ArrayList<T>(),new ArrayList<T>());
- }
- /**
- * Constructor
- *
- * @param context The current context.
- * @param resource The resource ID for a layout file containing a layout to use when
- * instantiating views.
- * @param textViewResourceId The id of the TextView within the layout resource to be populated
- */
- public CityAdapter(Context context, int resource, int textViewResourceId) {
- init(context, resource, textViewResourceId, new ArrayList<T>(),new ArrayList<T>());
- }
- /**
- * Constructor
- *
- * @param context The current context.
- * @param textViewResourceId The resource ID for a layout file containing a TextView to use when
- * instantiating views.
- * @param objects The objects to represent in the ListView.
- * @param objects2 城市拼音数组
- */
- public CityAdapter(Context context, int textViewResourceId, T[] objects,T[] objects2) {
- init(context, textViewResourceId, 0, Arrays.asList(objects),Arrays.asList(objects2));
- }
- /**
- * Constructor
- *
- * @param context The current context.
- * @param resource The resource ID for a layout file containing a layout to use when
- * instantiating views.
- * @param textViewResourceId The id of the TextView within the layout resource to be populated
- * @param objects The objects to represent in the ListView.
- */
- public CityAdapter(Context context, int resource, int textViewResourceId, T[] objects,T[] objects2) {
- init(context, resource, textViewResourceId, Arrays.asList(objects),Arrays.asList(objects2));
- }
- /**
- * Constructor
- *
- * @param context The current context.
- * @param textViewResourceId The resource ID for a layout file containing a TextView to use when
- * instantiating views.
- * @param objects The objects to represent in the ListView.
- */
- public CityAdapter(Context context, int textViewResourceId, List<T> objects,List<T> objects2) {
- init(context, textViewResourceId, 0, objects,objects2);
- }
- /**
- * Constructor
- *
- * @param context The current context.
- * @param resource The resource ID for a layout file containing a layout to use when
- * instantiating views.
- * @param textViewResourceId The id of the TextView within the layout resource to be populated
- * @param objects The objects to represent in the ListView.
- */
- public CityAdapter(Context context, int resource, int textViewResourceId, List<T> objects,List<T> objects2) {
- init(context, resource, textViewResourceId, objects, objects2);
- }
- /**
- * Adds the specified object at the end of the array.
- *
- * @param object The object to add at the end of the array.
- */
- public void add(T object) {
- if (mOriginalValues != null) {
- synchronized (mLock) {
- mOriginalValues.add(object);
- if (mNotifyOnChange) notifyDataSetChanged();
- }
- } else {
- mObjects.add(object);
- if (mNotifyOnChange) notifyDataSetChanged();
- }
- }
- /**
- * Inserts the specified object at the specified index in the array.
- *
- * @param object The object to insert into the array.
- * @param index The index at which the object must be inserted.
- */
- public void insert(T object, int index) {
- if (mOriginalValues != null) {
- synchronized (mLock) {
- mOriginalValues.add(index, object);
- if (mNotifyOnChange) notifyDataSetChanged();
- }
- } else {
- mObjects.add(index, object);
- if (mNotifyOnChange) notifyDataSetChanged();
- }
- }
- /**
- * Removes the specified object from the array.
- *
- * @param object The object to remove.
- */
- public void remove(T object) {
- if (mOriginalValues != null) {
- synchronized (mLock) {
- mOriginalValues.remove(object);
- }
- } else {
- mObjects.remove(object);
- }
- if (mNotifyOnChange) notifyDataSetChanged();
- }
- /**
- * Remove all elements from the list.
- */
- public void clear() {
- if (mOriginalValues != null) {
- synchronized (mLock) {
- mOriginalValues.clear();
- }
- } else {
- mObjects.clear();
- }
- if (mNotifyOnChange) notifyDataSetChanged();
- }
- /**
- * Sorts the content of this adapter using the specified comparator.
- *
- * @param comparator The comparator used to sort the objects contained
- * in this adapter.
- */
- public void sort(Comparator<? super T> comparator) {
- Collections.sort(mObjects, comparator);
- if (mNotifyOnChange) notifyDataSetChanged();
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public void notifyDataSetChanged() {
- super.notifyDataSetChanged();
- mNotifyOnChange = true;
- }
- /**
- * Control whether methods that change the list ({@link #add},
- * {@link #insert}, {@link #remove}, {@link #clear}) automatically call
- * {@link #notifyDataSetChanged}. If set to false, caller must
- * manually call notifyDataSetChanged() to have the changes
- * reflected in the attached view.
- *
- * The default is true, and calling notifyDataSetChanged()
- * resets the flag to true.
- *
- * @param notifyOnChange if true, modifications to the list will
- * automatically call {@link
- * #notifyDataSetChanged}
- */
- public void setNotifyOnChange(boolean notifyOnChange) {
- mNotifyOnChange = notifyOnChange;
- }
- private void init(Context context, int resource, int textViewResourceId, List<T> objects ,List<T> objects2) {
- mContext = context;
- mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- mResource = mDropDownResource = resource;
- mObjects = objects;
- mObjects2 = objects2;
- mFieldId = textViewResourceId;
- }
- /**
- * Returns the context associated with this array adapter. The context is used
- * to create views from the resource passed to the constructor.
- *
- * @return The Context associated with this adapter.
- */
- public Context getContext() {
- return mContext;
- }
- /**
- * {@inheritDoc}
- */
- public int getCount() {
- return mObjects.size();
- }
- /**
- * {@inheritDoc}
- */
- public T getItem(int position) {
- return mObjects.get(position);
- }
- /**
- * Returns the position of the specified item in the array.
- *
- * @param item The item to retrieve the position of.
- *
- * @return The position of the specified item.
- */
- public int getPosition(T item) {
- return mObjects.indexOf(item);
- }
- /**
- * {@inheritDoc}
- */
- public long getItemId(int position) {
- return position;
- }
- /**
- * {@inheritDoc}
- */
- public View getView(int position, View convertView, ViewGroup parent) {
- return createViewFromResource(position, convertView, parent, mResource);
- }
- private View createViewFromResource(int position, View convertView, ViewGroup parent,
- int resource) {
- View view;
- TextView text;
- if (convertView == null) {
- view = mInflater.inflate(resource, parent, false);
- } else {
- view = convertView;
- }
- try {
- if (mFieldId == 0) {
- // If no custom field is assigned, assume the whole resource is a TextView
- text = (TextView) view;
- } else {
- // Otherwise, find the TextView field within the layout
- text = (TextView) view.findViewById(mFieldId);
- }
- } catch (ClassCastException e) {
- Log.e("ArrayAdapter", "You must supply a resource ID for a TextView");
- throw new IllegalStateException(
- "ArrayAdapter requires the resource ID to be a TextView", e);
- }
- text.setText(getItem(position).toString());
- return view;
- }
- /**
- * <p>Sets the layout resource to create the drop down views.</p>
- *
- * @param resource the layout resource defining the drop down views
- * @see #getDropDownView(int, android.view.View, android.view.ViewGroup)
- */
- public void setDropDownViewResource(int resource) {
- this.mDropDownResource = resource;
- }
- /**
- * {@inheritDoc}
- */
- @Override
- public View getDropDownView(int position, View convertView, ViewGroup parent) {
- return createViewFromResource(position, convertView, parent, mDropDownResource);
- }
- /**
- * Creates a new ArrayAdapter from external resources. The content of the array is
- * obtained through {@link android.content.res.Resources#getTextArray(int)}.
- *
- * @param context The application's environment.
- * @param textArrayResId The identifier of the array to use as the data source.
- * @param textViewResId The identifier of the layout used to create views.
- *
- * @return An ArrayAdapter<CharSequence>.
- */
- public static ArrayAdapter<CharSequence> createFromResource(Context context,
- int textArrayResId, int textViewResId) {
- CharSequence[] strings = context.getResources().getTextArray(textArrayResId);
- return new ArrayAdapter<CharSequence>(context, textViewResId, strings);
- }
- /**
- * {@inheritDoc}
- */
- public Filter getFilter() {
- if (mFilter == null) {
- mFilter = new ArrayFilter();
- }
- return mFilter;
- }
- /**
- * <p>An array filter constrains the content of the array adapter with
- * a prefix. Each item that does not start with the supplied prefix
- * is removed from the list.</p>
- */
- private class ArrayFilter extends Filter {
- @Override
- protected FilterResults performFiltering(CharSequence prefix) {
- FilterResults results = new FilterResults();
- if (mOriginalValues == null) {
- synchronized (mLock) {
- mOriginalValues = new ArrayList<T>(mObjects);
- }
- }
- if (prefix == null || prefix.length() == 0) {
- synchronized (mLock) {
- ArrayList<T> list = new ArrayList<T>(mOriginalValues);
- results.values = list;
- results.count = list.size();
- }
- } else {
- String prefixString = prefix.toString().toLowerCase();
- final ArrayList<T> values = mOriginalValues;
- final int count = values.size();
- final ArrayList<T> newValues = new ArrayList<T>(count);
- for (int i = 0; i < count; i++) {
- final T value = values.get(i);
- final String valueText = value.toString().toLowerCase();
- final T value2 = mObjects2.get(i);
- final String valueText2 = value2.toString().toLowerCase();
-
- //查找拼音
- if(valueText2.startsWith(prefixString)){
- newValues.add(value);
- //查找汉字
- }else if(valueText.startsWith(prefixString)){
- newValues.add(value);
- }else{
-
- //添加汉字关联
- final String[] words = valueText.split(" ");
- final int wordCount = words.length;
-
- for (int k = 0; k < wordCount; k++) {
- if (words[k].startsWith(prefixString)) {
- newValues.add(value);
- break;
- }
- }
-
- //添加拼音关联汉字
- final String[] words2 = valueText2.split(" ");
- final int wordCount2 = words2.length;
- for (int k = 0; k < wordCount2; k++) {
- if (words2[k].startsWith(prefixString)) {
- newValues.add(value);
- break;
- }
- }
-
- }
-
- }
- results.values = newValues;
- results.count = newValues.size();
- }
- return results;
- }
- @SuppressWarnings("unchecked")
- @Override
- protected void publishResults(CharSequence constraint, FilterResults results) {
-
- mObjects = (List<T>) results.values;
- if (results.count > 0) {
- notifyDataSetChanged();
- } else {
- notifyDataSetInvalidated();
- }
- }
- }
- }
- cAdapter = new CityAdapter<String>(this,android.R.layout.simple_dropdown_item_1line, 汉字数组,拼音数组);
- autoView.setAdapter(cAdapter);
- autoView.setThreshold(1);
- //其中 autoView 为 AutoCompleteTextView
发表评论
-
Android里的音量调节
2013-04-01 13:37 1367步骤1:或许系统音量 ... -
Android Camera 方法分析
2012-03-29 10:52 3531Android Camera源码分析 android通 ... -
MyCameraActivity
2012-03-29 10:10 728package cn.fn; import android. ... -
MyCameraActivity
2012-04-01 13:27 910package cn.fn; import android. ... -
android AutoCompleteTextView+ SQLite
2012-03-21 13:33 1139android AutoCompleteTextView+ S ... -
android 异步回调加载网络图片
2012-03-20 11:50 966在做应用的时候很多时候都会去从网络加载图片,而且还要做各种各样 ... -
ProgressBar+AsyncTask 实现界面数据异步加载
2012-03-20 10:09 1650ProgressBar+AsyncTask 实现界面数据异步 ... -
Android 网络图片异步加载实例
2012-03-20 10:04 1014Android 网络图片异步加载实例 ... -
解决java.lang.OutOfMemoryError
2012-03-19 15:53 1118解决java.lang.OutOfMemoryError ... -
android Text 删除线
2012-03-16 19:35 1199import android.app.Activit ... -
android Gallery 详解
2012-03-14 14:17 1550android Gallery 正文 ... -
Android的线程使用来更新UI----Thread、Handler、Looper、TimerTask,Task,AsynTask等
2012-03-14 11:43 1471Android的线程使用来更新UI----Thread、Han ... -
AsyncTask的使用
2012-03-14 10:59 856AsyncTask的使用 ... -
Android控件开发之Gallery3D效果
2012-03-13 14:38 2976Android控件开发之Gal ... -
android GridView
2012-03-08 10:28 934主类 import android.app.Activi ... -
ListView异步加载图片是非常实用的方法
2012-03-08 10:09 988ListView异步加载图片是非常实用的方法,凡是是要通过网络 ... -
复制assets下的数据库到SD卡
2012-03-07 10:56 1258首先使用sqliteadDev(一个windows下图形化sq ... -
Android异步加载图像小结
2012-03-06 16:46 627Android异步加载图像小结 (1)由于an ... -
AutoCompleteTextView
2012-03-05 14:53 1457AutoCompleteTextView ... -
android 动态加载List
2012-03-05 11:11 1019main.xml <?xml ver ...
相关推荐
在Android开发中,`AutoCompleteTextView` 是一个非常常见的组件,它用于实现自动补全功能,通常用于输入框中提供用户可能输入的建议。在给定的标题“自定义AutoCompleteTextView下拉列表控件”中,我们可以理解为...
在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它允许用户在输入时自动显示匹配的建议列表,通常用于实现搜索框或者输入补全功能。`AutoCompleteTextView` 结合历史记录功能,可以提供更加人性化...
标题与描述均提到了“AutoCompleteTextView 显示更多”,这主要关注于如何优化AutoCompleteTextView在Android应用中的表现,特别是如何调整下拉建议列表的高度,以便在屏幕上显示更多的选项。以下将深入探讨这一主题...
AutoCompleteTextView是Android SDK提供的一种UI组件,用于在用户输入时提供下拉列表的自动提示功能,极大地提升了用户的输入体验。这个控件通常用于搜索框、地址输入等场景,可以根据用户输入的部分字符快速匹配出...
在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它允许用户在输入时自动显示匹配的建议列表,从而提升用户体验。本知识点主要关注如何实现`AutoCompleteTextView`与汉字和拼音的关联,使得用户可以...
在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它提供了自动补全功能,用户在输入时可以根据预设的数据集得到建议的匹配项。这篇文章将深入探讨`AutoCompleteTextView` 的工作原理以及如何结合...
AutoCompleteTextView是Android SDK提供的一种可以自动补全的文本输入框控件,它结合了EditText和ListView的功能,允许用户在输入时显示出与已输入内容匹配的建议列表。这个功能常见于许多应用程序,如搜索引擎、...
在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它提供了自动补全功能,用户在输入时可以接收到下拉列表的建议,提高了输入效率。`MultiAutoCompleteTextView` 是 `AutoCompleteTextView` 的扩展,...
本文将详细介绍如何在Android中仿照百度和谷歌的自动提示功能,利用`AutoCompleteTextView`控件来实现这一功能。 `AutoCompleteTextView`是Android SDK中的一个视图组件,它继承自`EditText`,增加了自动补全的功能...
AutoCompleteTextView是Android SDK提供的一种用于输入文本时自动补全的视图组件,它扩展了EditText,能够根据用户输入的部分文字动态显示出匹配的建议列表。这个功能在许多应用中非常常见,例如搜索引擎、地址...
在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它允许用户在输入时自动显示匹配的建议列表,从而提升用户体验。本教程将详细讲解如何利用`AutoCompleteTextView` 实现中文和拼音关联的自动提示...
在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它允许用户在输入时自动显示匹配的建议列表。通常,我们使用`ArrayAdapter`来连接数据源和`AutoCompleteTextView`,但有时默认的功能可能无法满足...
在Android开发中,`AutoCompleteTextView` 是一个非常实用的组件,它允许用户在输入时自动显示匹配的建议列表,极大地提高了用户体验。本篇将详细讲解`AutoCompleteTextView`如何用于自动提示联系人信息,并结合从...
在Android开发中,AutoCompleteTextView和TextWatcher是两个非常重要的组件,它们可以帮助我们实现丰富的文本输入交互功能。本文将深入探讨这两个组件,并结合实例展示如何将它们结合起来使用,以实现关键词下拉提示...
在Android开发中,AutoCompleteTextView是一个非常实用的控件,它允许用户在输入时自动显示匹配的建议列表,极大地提高了用户体验。本实例将深入探讨如何使用AutoCompleteTextView,并结合具体的...
AutoCompleteTextView是Android系统提供的一种可以自动补全的文本输入控件,它允许用户在输入时根据已有的数据集匹配并显示建议的选项。这个功能通常用于搜索框、地址输入等场景,提升用户体验。在本主题中,我们将...
AutoCompleteTextView是Android SDK提供的一种视图组件,用于在用户输入文本时提供下拉列表的自动补全功能。它能够极大地提升用户体验,特别是在用户需要从大量预定义选项中选择时。在开发移动应用,尤其是涉及搜索...