首页 > 代码库 > adapter
adapter
1、android widget基础适配器 Adapter
public interface Adapter {注册数据集观察者,以便监听数据变动。
void registerDataSetObserver(DataSetObserver observer); 注销数据集观察者void unregisterDataSetObserver(DataSetObserver observer); 获取数据集里数据项的数量int getCount(); 获取指定position位置数据项Object getItem(int position); 获取数据项的IDlong getItemId(int position); 数据集是否固定boolean hasStableIds(); 从数据集指定位置获取一个VIEW用来显示数据,你既可以通过创建一个VIEW也可以通过XML资源文件来inflate。当你通过XML资源文件创建时,默认的父VIEW给这个VIEW提供默认的LAYOUT参数,当然你也可以通过
android.view.LayoutInflater#inflate(int, android.view.ViewGroup, boolean)
来指定一个父view。
position:指定的位置convertView:为了重复使用VIEW,当原来的VIEW和现在要使用的VIEW类型一致时,不需要转换,只需要更改内容就可以,当类型不一样时,需要重新创建一个新类型的VIEW以便显示数据。
parent:指定的父VIEW。View getView(int position, View convertView, ViewGroup parent); static final int IGNORE_ITEM_VIEW_TYPE = AdapterView.ITEM_VIEW_TYPE_IGNORE;获取指定位置数据项显示VIEW的类型
int getItemViewType(int position); 获取总共VIEW的类型数量int getViewTypeCount(); static final int NO_SELECTION = Integer.MIN_VALUE; 判断是否为空boolean isEmpty(); }
2、SpinnerAdapter
public interface SpinnerAdapter extends Adapter { /** * <p>Get a {@link android.view.View} that displays in the drop down popup * the data at the specified position in the data set.</p> * * @param position index of the item whose view we want. * @param convertView the old view to reuse, if possible. Note: You should * check that this view is non-null and of an appropriate type before * using. If it is not possible to convert this view to display the * correct data, this method can create a new view. * @param parent the parent that this view will eventually be attached to * @return a {@link android.view.View} corresponding to the data at the * specified position. */ public View getDropDownView(int position, View convertView, ViewGroup parent); }
3、ListAdapter
public interface ListAdapter extends Adapter { /** * Indicates whether all the items in this adapter are enabled. If the * value returned by this method changes over time, there is no guarantee * it will take effect. If true, it means all items are selectable and * clickable (there is no separator.) * * @return True if all items are enabled, false otherwise. * * @see #isEnabled(int) */ public boolean areAllItemsEnabled(); /** * Returns true if the item at the specified position is not a separator. * (A separator is a non-selectable, non-clickable item). * * The result is unspecified if position is invalid. An {@link ArrayIndexOutOfBoundsException} * should be thrown in that case for fast failure. * * @param position Index of the item * * @return True if the item is not a separator * * @see #areAllItemsEnabled() */ boolean isEnabled(int position); }
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。