Comments (9)
刚重新试了下, 确实如你所说, 之前应该是我使用的问题,看来我得好好看下源码了, 非常感谢
from superadapter.
你好,demo中有addAll的使用情况(具体在第4个tab的menu菜单中),看你的log应该是布局出了问题,能贴下相关代码吗
from superadapter.
我使用SingleAdapter能正常显示, 复写了IMulItemViewType接口后就报上面的异常, 然后我完全参照demo写的Adapter,只是布局不同,布局代码如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/deviceName"
android:textColor="@color/device_list_text_bg"
android:textSize="14sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@+id/deviceImgLayout"
android:layout_below="@id/deviceName"
android:layout_marginTop="8dp"
android:background="@drawable/green_stroke_white_solid_bg"
android:layout_width="130dp"
android:layout_height="100dp">
<ImageView
android:layout_gravity="center"
android:id="@+id/deviceImg"
tools:src="@mipmap/ic_launcher"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
<TextView
android:id="@+id/deviceLeftLabel"
android:layout_alignTop="@id/deviceImgLayout"
android:layout_toRightOf="@id/deviceImgLayout"
android:layout_marginLeft="10dp"
android:textSize="12sp"
android:textColor="@color/black_4a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/deviceLeftTv"
tools:text="100%"
android:layout_marginTop="2dp"
android:textColor="@color/main_green"
android:textSize="24sp"
android:layout_alignLeft="@id/deviceLeftLabel"
android:layout_below="@id/deviceLeftLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/deviceSpeedLabel"
android:textSize="12sp"
android:textColor="@color/device_list_text_bg"
android:layout_alignLeft="@id/deviceLeftLabel"
android:layout_below="@id/deviceLeftLabel"
android:layout_marginTop="44dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/deviceSpeedTv"
android:layout_toRightOf="@id/deviceSpeedLabel"
android:layout_alignBottom="@id/deviceSpeedLabel"
android:layout_marginLeft="6dp"
android:textSize="14sp"
android:textColor="@color/main_green"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_alignLeft="@id/deviceLeftLabel"
android:layout_alignBottom="@id/deviceImgLayout"
android:layout_marginBottom="4dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.common.views.FontIconView
android:id="@+id/deviceSpeedLowIcon"
android:text="@string/icon_font_speed_low"
android:textSize="14.6sp"
android:textColor="@color/device_list_icon_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.common.views.FontIconView
android:id="@+id/deviceSpeedMidIcon"
android:text="@string/icon_font_speed_mid"
android:textSize="14.6sp"
android:layout_marginLeft="6dp"
android:textColor="@color/device_list_icon_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.common.views.FontIconView
android:id="@+id/deviceSpeedHighIcon"
android:text="@string/icon_font_speed_high"
android:textSize="14.6sp"
android:layout_marginLeft="6dp"
android:textColor="@color/device_list_icon_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<com.common.views.FontIconView
android:id="@+id/deviceSpeedSleepIcon"
android:text="@string/icon_font_speed_sleep"
android:textSize="14.6sp"
android:textColor="@color/device_list_icon_bg"
android:layout_marginLeft="6dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<FrameLayout
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="30dp"
android:background="@mipmap/switch_bg"
android:layout_width="48dp"
android:layout_height="48dp">
<ImageView
android:id="@+id/deviceSwitchIcon"
android:src="@mipmap/switch_off"
android:layout_gravity="center"
android:layout_marginLeft="0.5dp"
android:layout_width="22dp"
android:layout_height="22dp" />
</FrameLayout>
<ImageView
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:src="@drawable/arrow_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
from superadapter.
你的adapter中的holder使用到的ID必须在布局文件中存在哦,如果方便,贴下adapter相关的代码。
from superadapter.
我觉得不是这个问题, 因为我只要使用SuperAdapter(Context context, List<T> items, int layoutResId)
这个构造函数就能正常显示; 如果别的代码不改, 将布局文件及onBind替换成demo中的也能正常显示,下面是Adapter的代码:
static class SingleAdapter extends SuperAdapter<DeviceInfo> {
Context context;
public SingleAdapter(Context context, List<DeviceInfo> items, int resId) {
super(context, items, resId);
this.context = context;
}
@Override
public void onBind(SuperViewHolder holder, int viewType, int position, DeviceInfo item) {
if (viewType == 0) {
holder.setText(R.id.deviceName, item.nickName);
ImageView imageView = holder.getView(R.id.deviceImg);
Glide.with(context).load(item.picUrl).into(imageView);
holder.setText(R.id.deviceLeftTv, "95%");
holder.setText(R.id.deviceSpeedTv, "中速");
}
}
}
static class SingleAdapter extends SuperAdapter<DeviceInfo> {
Context context;
public SingleAdapter(Context context, List<DeviceInfo> items, IMulItemViewType<DeviceInfo> mulItemViewType) {
super(context, items, mulItemViewType);
this.context = context;
}
@Override
public void onBind(SuperViewHolder holder, int viewType, int position, DeviceInfo item) {
// if (viewType == 0) {
holder.setText(R.id.deviceName, item.nickName);
ImageView imageView = holder.getView(R.id.deviceImg);
Glide.with(context).load(item.picUrl).into(imageView);
holder.setText(R.id.deviceLeftTv, "95%");
holder.setText(R.id.deviceSpeedTv, "中速");
// }
}
@Override
protected IMulItemViewType<DeviceInfo> offerMultiItemViewType() {
return new IMulItemViewType<DeviceInfo>() {
@Override
public int getViewTypeCount() {
return 2;
}
@Override
public int getItemViewType(int position, DeviceInfo info) {
if (position % 2 == 0) {
return 0;
}
return 1;
}
@Override
public int getLayoutId(int viewType) {
if (viewType == 0) {
return R.layout.main_device_list_item;
}
return R.layout.main_device_list_item;
}
};
}
}
from superadapter.
你的两个布局文件是一样的啊? 你可以尝试检查一下Adapter所在的Activity或者Fragment类的布局文件,我觉得跟这个库的关系不大,参见stackoverflow
from superadapter.
开始没有重写offerMultiItemViewType(),报了一样的异常,还以为是布局的问题,给改成一样了, 现已解决, thx。
PS: 为何在使用时既要传IMulItemViewType, 又要在offerMultiItemViewType()覆盖掉IMulItemViewType呢?
from superadapter.
PS: 为何在使用时既要传IMulItemViewType, 又要在offerMultiItemViewType()覆盖掉IMulItemViewType呢?
这两个只要提供一个就行了,不用都写。如果在adapter中override了,在创建adapter的时候传个null就好了。 还有你不用在自己的adapter维持一个context
的引用,SuperAdapter内部提供了一个mContext
变量和一个getContext()
供你调用。 : )
from superadapter.
不用客气,有什么问题请联系我 : ) 基本使用 看一遍应该就能愉快地玩耍了。
from superadapter.
Related Issues (20)
- 为什么没有setNewData这类方法? HOT 4
- 在 index=0 的位置插入数据无法直接添加 item HOT 7
- ViewHolder里面添加自己想要的方法 HOT 2
- 期待增加以下几个功能 HOT 3
- 3.1->3.2 更新了什么东西? HOT 4
- 加载网络图片 HOT 2
- bug真的有点多... HOT 3
- RecyclerView怎样更改当前item的值? HOT 6
- Note: Do not bind click listener in onBind(). 不要在onBind()中绑定点击事件. HOT 1
- Error:(29, 13) Failed to resolve: org.byteam.superadapter:superadapter:latestVersion HOT 3
- addAll 方法里面增加一个清空并添加的方法 HOT 4
- 请问支持DataBinding吗 HOT 1
- support-v7:24.2.0 新增adapter工具类DiffUtil 建议加入,成倍提高效率 HOT 2
- 以非常快的速度点击的时候,得到的position可能会是-1 HOT 3
- 提个场景不知道这样的改进好不好 HOT 1
- 用了这个适配器,Item点击的水波纹效果消失了。。。 HOT 4
- 在demo里 listview set SingleAdapter后 在SuperViewHolder里绑定事件时 holder.getAdapterPosition() 一直是-1 HOT 11
- setOnClickListener Position为-1 HOT 4
- replaceAll(List<T> items) 方法会闪动一下 HOT 1
- 添加footer 遇见这个问题 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from superadapter.