hongyangandroid / baseadapter Goto Github PK
View Code? Open in Web Editor NEWAndroid 万能的Adapter for ListView,RecyclerView,GridView等,支持多种Item类型的情况。
License: Apache License 2.0
Android 万能的Adapter for ListView,RecyclerView,GridView等,支持多种Item类型的情况。
License: Apache License 2.0
经过分析发现是viewHolder.getAdapterPosition();返回了NO_POSITION也就是-1,导致item点击事件时调用mDatas.get(postion)报错,偶尔会莫名其妙的出现
鸿洋大神。我把代码邮箱发你了。希望能指点一下因为有个毛病改不过来:(
add heads添加View 布局 不可以居中。
网络图片加载出现错位
毕竟上拉下拉刷新是非常常用的一个需求,有些项目中几乎全部是需要上拉下拉的,谢谢
View footer = LayoutInflater.from(getContext()).inflate(R.layout.view_agio_footer, null);
headerAndFooterWrapper.addFootView(footer);
view_agio_footer里面的布局不能居中,因为在activity 里面 拿不到parent
在CommonAdapter中添加操作数据的函数?
public void addAll(Collection<? extends T> collections) {
datas.addAll(collections);
}
public void add(T t) {
datas.add(t);
}
public void add(int position, T t) {
datas.add(position, t);
}
public void clear() {
datas.clear();
}
Error:failed to find Build Tools revision 23.0.0 rc3 <a href="install.build.tools">Install Build Tools 23.0.0 rc3 and sync project</a>
错误提示。点击之后的的错误弹窗提示:
All packages are not available for download! The following packages are not available:
- Package id build-tools;23.0.0-preview
ps:我的是可以直接翻墙的,所以应该不是网络环境的问题
@hongyangAndroid AdapterDelegates听说要升级到3.0了,现在baseAdapter已经采用了AdapterDelegates来实现,那么应该如何处理不同viewtype的decoration呢?
我的数据显示,大概一个屏幕可以显示12条。但是,如果我第一加载的数据长度只有6条,加载更多会被立马调用。这算是一个bug么,求大神解决。
建议添加 删除指定position或者view的 api功能,有时候添加多个header,操作时会选择删除部分
Sample中的RvWidthHeaderActivity,如果使用
mRecyclerView.setLayoutManager(new GridLayoutManager(this,2));
header作为一个Item存在,就不是header了
adapter.setOnItemClickListener
为什么要实现onItemLongClick呢,这个还是比较少用到吧,建议分成两个,
一个setOnItemClickListener
一个setOnItemLongClickListener
protected List mDatas;在CommonAdapter还有定义,而convert使用的数据是MultiItemTypeAdapter中的mDatas,这样容易出现改变数据时,刷新后RecyclerView没有改变,其实改变只是CommonAdapter中定义的mDatas。这个mDatas具体的作用是?
鸿洋,以前一直用com.joanzapata.android:base-adapter-helper,感觉挻好用,但不支持多布局和RecyclerView,GridView之类的。
您这个很不错,建议添加上显示“加载更多”的 footerView 视图,毕竟这个项目中这个功能一般都通用。
当使用横向recyclerview的时候,可能会动态设置itemView的大小(比如我一个屏幕只显示3列),能不能提供一个方法设置呢 一般的adapter是在onCreateViewHolder那里设置View的layoutparams的
请问怎么获取absListView中当前的position,没有暴露方法呢
viewHolder.setText(R.id.tv_yield, spannableString); //剩余 期限
不能用 SpannableString做为字符串传入
嗨,鸿神,打扰了;昨天看到您新封装的对RecyclerView的通用adapter;其中的可以添加分类header的那种情况;我现在有个需求:实现header浮动(下一个header推走上一个header,同时header上有按钮能够点击),这种在您这个封装基础上如何实现?麻烦您给指点指点,谢谢
建议在ViewHolder中加一个item点击事件以免ListView中包含GridView这种情况下无法处理里面的点击事件
如题
等加载完成之后点击就又没有问题了
07-13 11:12:22.116 6026-6026/com.movieapp E/AndroidRuntime: FATAL EXCEPTION: main java.lang.IndexOutOfBoundsException: Invalid index 118, size is 118 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) at java.util.ArrayList.get(ArrayList.java:308) at com.zhy.adapter.recyclerview.MultiItemTypeAdapter$1.onClick(MultiItemTypeAdapter.java:72) at android.view.View.performClick(View.java:4240) at android.view.View$PerformClick.run(View.java:17752) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5473) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:691) at dalvik.system.NativeStart.main(Native Method)
如题
我的listview的每一个项是一个Gridview,在Demo中美看的如何使用,所以请教一下这种情况要怎么使用啊 ?
当获取到比前一次更多的数据的时候,直接使用adapter.notifyDataSetChanged();刷新界面,无法正确显示。而在MultiItemTypeAdapter类中添加了下面这个方法,然后重新传入之后,就可以正确显示。
public void setDatas(List datas){
this.mDatas = datas;
this.notifyDataSetChanged();
}
如果没有添加这个方法,而是直接对存储数据的集合进行添加进数据,然后再调用adapter.notifyDataSetChanged();并没有效果。更多的是需要在上拉加载更多的时候使用
ViewHolder的辅助方法应该判断View的类型再强转成TextView或者ImageView之类的
刚开始用github,不太怎么会弄fork,见谅
多种Item的时候不明白为什么要考虑抽出一个接口,然后再重新弄一个类,这样是不是把类弄太多了不好,
我个人把她整到一块了,请鸿神点评。
public abstract class CommonAdapter extends BaseAdapter {
/**
* 上下文对象
/
protected Context context;
/*
* 单Item的时候,Item xml的ID
/
protected int layoutItemID;
/*
* Item填充数据
*/
protected List lDatas;
/**
* 多Item时构造函数
*
* @param context 山下文
* @param lDatas Item数据集
*/
public CommonAdapter(Context context, List<T> lDatas) {
this.context = context;
this.lDatas = lDatas;
}
/**
* 单Item Type时构造函数
*
* @param context 上下文
* @param lDatas Item数据集
* @param layoutItemID Item xml布局文件ID
*/
public CommonAdapter(Context context, List<T> lDatas, int layoutItemID) {
this.context = context;
this.lDatas = lDatas;
this.layoutItemID = layoutItemID;
}
@Override
public int getCount() {
return lDatas.size();
}
@Override
public T getItem(int position) {
return lDatas.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
return layoutItemID;
}
@Override
public int getViewTypeCount() {
return 1;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
int itemID = getItemViewType(position);
ViewHolder holder = ViewHolder.getInstance(context, convertView,
parent, itemID, position);
getViewItem(holder, getItem(position));
return holder.getConvertView();
}
/**
* 给每个Item设置数据
*
* @param holder holder句柄对象
* @param item item每一项数据值
*/
public abstract void getViewItem(ViewHolder holder, T item);
}
谁的多布局会用多个实体类呢 ?这设计得不咋样。
item 无法响应 listview 的点击事件为何啊????原生的可以响应?
如题。。。
当采用LoadMoreWrapper时,有时会根据服务器返回的数据来判断有没有下一页,如果没有的话,需要隐藏掉 loadMoreView,能否提供一个api实现呢
但我使用多item布局,且使用HeaderAndFooterWrapper
加入了头部,我的Adapter extends MultiItemTypeAdapter
,
在RecyclerView.LayoutManager manager = recyclerView.getLayoutManager(); if (manager instanceof GridLayoutManager) { final GridLayoutManager gridLayoutManager = (GridLayoutManager) manager; gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { @Override public int getSpanSize(int position) { LogUtils.e("position:" + position); int viewType = getItemViewType(position);
会出现数组越位的情况
public ItemViewDelegate getItemViewDelegate(T item, int position) { int delegatesCount = delegates.size(); for (int i = delegatesCount - 1; i >= 0; i--) { ItemViewDelegate<T> delegate = delegates.valueAt(i); if (delegate.isForViewType(item, position)) { return delegate; } } throw new IllegalArgumentException( "No ItemViewDelegate added that matches position=" + position + " in data source"); }
这个方法根据item以及position通过isForViewType判断是哪一个Delegate,但是如果有大于2种类型的话,isForViewType的返回值是布尔类型的,就不够用了。
自己也尝试了很多方法,就是没法隐藏,希望大神能给个解法
适配器里面用 glide 加载图的时候 ,上下滑动,图片一会大一会小,ImageView的大小在变化。感觉像是item 的复用的问题。
adapter = new MultiItemTypeAdapter(getActivity(), data);
adapter.addItemViewDelegate(new HotNewSalesItemDelagate());
adapter.addItemViewDelegate(new HotSalesItemDelagate());
View header_view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_hot_new_header, null);
initHeaderView(header_view);
wrapper = new HeaderAndFooterWrapper(adapter);
wrapper.addHeaderView(header_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(wrapper);
wrapper.notifyDataSetChanged();
多种类型的列表适配器SectionAdapter貌似没有体现出来
多布局Item只要根据不同的layoutId判断然后给不同布局里的控件赋值即可,为什么还要提供这两个方法呢
这个文件的构造函数调用父类的,
public SectionAdapter(Context context, int layoutId, MultiItemTypeSupport multiItemTypeSupport, List<T> datas, SectionSupport sectionSupport)
{
super(context, datas, null);
......
}
在父类中判断这个为空直接异常。
public MultiItemCommonAdapter(Context context, List<T> datas,
MultiItemTypeSupport<T> multiItemTypeSupport)
{
super(context, -1, datas);
mMultiItemTypeSupport = multiItemTypeSupport;
if (mMultiItemTypeSupport == null)
throw new IllegalArgumentException("the mMultiItemTypeSupport can not be null.");
}
不知是写错还是什么原因?
mLoadMoreWrapper.setLoadMoreView(R.layout.item_universal_more);
mLoadMoreWrapper.setOnLoadMoreListener(new LoadMoreWrapper.OnLoadMoreListener(){
@Override
public void onLoadMoreRequested(){
});
一开始就在加载,这个不应该是滑动到最底部才触发吗?
毕竟上拉下拉刷新是非常常用的一个需求,有些项目中几乎全部是需要上拉下拉的,谢谢
mEmptyWrapper = new EmptyWrapper(mAdapter);
mEmptyWrapper.setEmptyView(R.layout.empty_view);
1. recycleview.setAdapter(mAdapter);
2.// recycleview.setAdapter(mEmptyWrapper);
如果是第一种写法不加包装类是没问题的,notifyDataSetChanged(); 界面及时更新
如果是第二种写法,那么界面不会有反应,需在往下拖动,然后拖回来,界面才会有刷新
为什么调用了adapter.notifyDataSetChanged() 数据没有更新,用的CommAdapter
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.