- 浏览: 5776996 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (890)
- WindowsPhone (0)
- android (88)
- android快速迭代 (17)
- android基础 (34)
- android进阶 (172)
- android高级 (0)
- android拾遗 (85)
- android动画&效果 (68)
- Material Design (13)
- LUA (5)
- j2me (32)
- jQuery (39)
- spring (26)
- hibernate (20)
- struts (26)
- tomcat (9)
- javascript+css+html (62)
- jsp+servlet+javabean (14)
- java (37)
- velocity+FCKeditor (13)
- linux+批处理 (9)
- mysql (19)
- MyEclipse (9)
- ajax (7)
- wap (8)
- j2ee+apache (24)
- 其他 (13)
- phonegap (35)
最新评论
-
Memories_NC:
本地lua脚本终于执行成功了,虽然不是通过redis
java中调用lua脚本语言1 -
ZHOU452840622:
大神://处理返回的接收状态 这个好像没有监听到 遇 ...
android 发送短信的两种方式 -
PXY:
拦截部分地址,怎么写的for(int i=0;i<lis ...
判断是否登录的拦截器SessionFilter -
maotou1988:
Android控件之带清空按钮(功能)的AutoComplet ...
自定义AutoCompleteTextView -
yangmaolinpl:
希望有表例子更好。。。,不过也看明白了。
浅谈onInterceptTouchEvent、onTouchEvent与onTouch
看看人家怎么写的。
/* * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package qianlong.qlmobile.ui; import android.content.Context; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Filter; import android.widget.Filterable; import android.widget.TextView; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Comparator; import java.util.Collections; /** * A ListAdapter that manages a ListView backed by an array of arbitrary * objects. By default this class expects that the provided resource id references * a single TextView. If you want to use a more complex layout, use the constructors that * also takes a field id. That field id should reference a TextView in the larger layout * resource. * * However the TextView is referenced, it will be filled with the toString() of each object in * the array. You can add lists or arrays of custom objects. Override the toString() method * of your objects to determine what text will be displayed for the item in the list. * * To use something other than TextViews for the array display, for instance, ImageViews, * or to have some of data besides toString() results fill the views, * override {@link #getView(int, View, ViewGroup)} to return the type of view you want. */ public class ArrayAdapter<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; /** * 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 ArrayAdapter(Context context, int textViewResourceId) { init(context, textViewResourceId, 0, 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 ArrayAdapter(Context context, int resource, int textViewResourceId) { init(context, resource, textViewResourceId, 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. */ public ArrayAdapter(Context context, int textViewResourceId, T[] objects) { init(context, textViewResourceId, 0, Arrays.asList(objects)); } /** * 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 ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) { init(context, resource, textViewResourceId, Arrays.asList(objects)); } /** * 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 ArrayAdapter(Context context, int textViewResourceId, List<T> objects) { init(context, textViewResourceId, 0, objects); } /** * 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 ArrayAdapter(Context context, int resource, int textViewResourceId, List<T> objects) { init(context, resource, textViewResourceId, objects); } /** * 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(); } } /** * Adds the specified Collection at the end of the array. * * @param collection The Collection to add at the end of the array. */ public void addAll(Collection<? extends T> collection) { if (mOriginalValues != null) { synchronized (mLock) { mOriginalValues.addAll(collection); if (mNotifyOnChange) notifyDataSetChanged(); } } else { mObjects.addAll(collection); if (mNotifyOnChange) notifyDataSetChanged(); } } /** * Adds the specified items at the end of the array. * * @param items The items to add at the end of the array. */ public void addAll(T ... items) { if (mOriginalValues != null) { synchronized (mLock) { for (T item : items) { mOriginalValues.add(item); } if (mNotifyOnChange) notifyDataSetChanged(); } } else { for (T item : items) { mObjects.add(item); } 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) { mContext = context; mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mResource = mDropDownResource = resource; mObjects = objects; 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); } T item = getItem(position); if (item instanceof CharSequence) { text.setText((CharSequence)item); } else { text.setText(item.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(); // First match against the whole, non-splitted value 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; } } } } results.values = newValues; results.count = newValues.size(); } return results; } @Override protected void publishResults(CharSequence constraint, FilterResults results) { //noinspection unchecked mObjects = (List<T>) results.values; if (results.count > 0) { notifyDataSetChanged(); } else { notifyDataSetInvalidated(); } } } }
发表评论
-
http://www.android-studio.org/
2018-08-06 09:25 0http://www.android-studio.org/ ... -
SlidingDrawer源码
2012-03-14 10:13 3773我把SlidingDrawer源码提了出来,希望对1.5的朋友 ... -
简单拖动效果(带Cache,需要完善)
2011-10-13 15:10 4181如何去实现一个具有幻象的拖拽效果? 所谓”幻象“就是当你按下去 ... -
Android Activity中启动另一应用程序的方法,无需得到类名
2011-08-02 14:46 17197在网上搜索了一会相关的实现代码,发现所有的文章都说是需要包名和 ... -
java-universal-tween-engine,一个动画系统库
2011-06-29 09:21 6699http://code.google.com/p/java-u ... -
网上发现的一个android UI包
2011-05-24 12:21 4049里面有些UI和效果 -
android中使用代码启动其他程序
2011-04-29 23:15 5221你要訪問其他的程序,那麼這個程序要先裝載到模擬器或真機上面,因 ... -
listView背景问题以及限制editText字数以及如果想通知别人已经不能在写
2011-04-29 22:44 31601.在listView设置好背景之后 你如果点击空白出 你会发 ... -
Android键盘和触摸事件处理
2011-04-29 22:32 6963activity和VIEW都能接收触摸和按键,如果响应事件只需 ... -
Android的绘制文本对象FontMetrics的介绍及绘制文本
2011-04-29 22:29 11459一。Android绘制文本对象FontMetrics介绍 ... -
Android View 拖动&插入
2011-04-29 22:20 3505View 拖动&插入 即: 支持 拖动图标 然后 ... -
使TextView文本可以水平和垂直滚动
2011-04-29 21:59 14334在做一个小的电子书程序,要求电子书具有放大缩小的功能,所以肯定 ... -
Android下获取开机时间
2011-04-02 21:51 6184找了一圈没发现能得到开机启动时间资料,于是乎突发奇想,得到了解 ... -
AutoCompleteTextView连接到数据库
2011-03-30 20:49 4653AutoCompleteTextView可以根据输入 ... -
改变屏幕Brightness(亮度)
2011-03-30 12:48 4563http://www.eoeandroid.com/forum ... -
android 拖拽图片&拖动浮动按钮到处跑
2011-02-24 20:55 31703来自老外: import android.app.Acti ... -
拖动一个控件在另一个控件(layout)上,并固定位置在几个位置显示
2011-02-24 20:51 5847实现效果: 鼠标拖动btn SSS,SSS在水平的layo ... -
Handler与Message类,实现n秒后无操作自动消失功能
2011-02-24 20:45 4593实现功能:某控件不操作10秒后,自动消失。如照相机变焦条出现后 ... -
带删除按钮的ListView
2011-02-24 10:33 6112不用说了,上图先: import java.util.A ... -
android3.0之Action Bar基础
2011-02-22 17:12 6793http://www.android123.com.cn/an ...
相关推荐
ArrayAdapter 源码
Android 应用开发源码 参考与学习使用
安卓Android源码——(列表之ArrayAdapter适配).zip
安卓Android源码——(列表ArrayAdapter适配).zip
ListView使用ArrayAdapter适配器源码
Android ListView列表之ArrayAdapter适配Demo源码.rar
Android应用源码之(列表之ArrayAdapter适配).zip项目安卓应用源码下载Android应用源码之(列表之ArrayAdapter适配).zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目...
安卓Android源码——(列表ArrayAdapter适配).rar
android 源码学习. 资料部分来源于合法的互联网渠道收集和整理,供大家学习参考与交流。本人不对所涉及的版权问题或内容负法律责任。如有侵权,请通知本人删除。感谢CSDN官方提供大家交流的平台
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,...
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,...
Android应用源码开发Demo,主要用于毕业设计学习。
Android源码:ListView组件应用演示代码,layout的xml文件名需要全部小写。 ActivityList1: 1.初步介绍ListView这个组件。 2.初步介绍ArrayAdapter。 # simple_list_item_single_choice # ...
NULL 博文链接:https://aarongo.iteye.com/blog/1919251
60个Android开发精典案例 Android软件源码: 2-1(Activity生命周期) 3-1(Button与点击监听器) 3-10-1(列表之ArrayAdapter适配) 3-10-2(列表之SimpleAdapter适配) 3-11(Dialog对话框) 3-12-5(Activity跳转与操作) 3-12...
11:万能适配器BaseAdapter以及ArrayAdapter等适配器的使用 12:android美化方面关于selector的使用 13:简单动画的使用 14:广播接收器BroadCastReceiver接收腾讯授权码的应用. 15:腾讯Oauth认证的使用(新浪的,...
Android下拉刷新上拉加载源码 ....... @Override public void onRefresh() { mHandler.postDelayed(new Runnable() { @Override public void run() { start = ++refreshCnt; items.clear(); ...
NULL 博文链接:https://2528.iteye.com/blog/838329