在adapter中使用报错
jun201607 opened this issue · comments
问题描述
SwipeConsumer consumer = SmartSwipe.wrap(view)该行代码报错:NullPointerException: Layout parameters cannot be null
-
预期行为:recyclerview增加侧滑删除按钮
-
实际行为:运行崩溃
出问题的代码
public ViewHolder onCreateViewHolder(@nonnull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.buy_course_list_inner_item, null);
TextView textView = new TextView(context);
textView.setBackgroundColor(0xFFAA0000);
textView.setTextColor(0xFFFFFFFF);
textView.setTextSize(14);
textView.setGravity(Gravity.CENTER);
// textView.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.MATCH_PARENT));
SwipeConsumer consumer = SmartSwipe.wrap(view)
.addConsumer(new SlidingConsumer())
.setHorizontalDrawerView(textView);
// .addToExclusiveGroup(exclusiveGroup);
return new ViewHolder(view);
### 当前使用的SmartSwipe版本号:
例如: **1.0.8**
### 如何复现?(如果能在demo中复现将有利于作者尽快修复问题)
### 截图或gif
(提交issue前请删除本行文字)有时候,一图胜千言,为了更高效的沟通,请将您认为有助于说明问题的截图或者gif图片贴在此处吧!
>>>>>>>>>>>>>> 提交issue前请删除以下内容 <<<<<<<<<<<<<<<
=========== 小贴士 ============
将图片贴到issue中有以下几种方式:
1. 复制图片后,在issue文本输入框中Ctrl + V (mac: command + V)粘贴,github会自动上传图片并添加为其markdown格式
2. 从文件夹中拖动图片到issue的文本输入框中,效果同上
3. 如果是一个在线图片,可在issue输入框中输入图片地址,markdown格式为: ![图片的描述](图片的地址)
@jun201607 改以下2处:
View view = LayoutInflater.from(context).inflate(R.layout.buy_course_list_inner_item, null);
//.......
return new ViewHolder(view);
改成
View view = LayoutInflater.from(context).inflate(R.layout.buy_course_list_inner_item, parent, false);
//.......
return new ViewHolder(consumer.getWrapper());