我有一个listview,因为我有对cardviews的recylerview ...当我选择其中任何一个时,那么浮动布局应该在那里有3个按钮。我正在使用这个库enter link description here。
我在适配器中使用此库并在活动中设置了该适配器,但是一旦我进入活动,应用程序就会崩溃 NullPointerException 。出现错误的是,当我给两个xml文件充气但是我想首先膨胀 abc_card_view_video 然后点击其中的任何一个新文件 hover_card_view 应该膨胀但是旧文件应该在后台。
帮我摆脱它。感谢
public class LessonVideoAdapter extends RecyclerView.Adapter<LessonDataHolder> {
private List<VideoList> slipList;
private Context mContext;
public BlurLayout samplelayout;
public LessonVideoAdapter() {
slipList = new ArrayList<>();
slipList.add(new VideoList("Chapter 1", R.drawable.demo_one));
slipList.add(new VideoList("Chapter 2", R.drawable.demo_two));
slipList.add(new VideoList("Chapter 3", R.drawable.demo_one));
}
@Override
public LessonDataHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.abc_card_view_video, parent, false);
return new LessonDataHolder(view);
}
@Override
public void onBindViewHolder(LessonDataHolder holder, int position) {
VideoList s = slipList.get(position);
holder.bindSlip(s);
}
@Override
public int getItemCount() {
return slipList.size();
}
}
class LessonDataHolder extends RecyclerView.ViewHolder {
private TextView nameOfSlip;
private ImageView slipImage;
private Context context;
public LessonDataHolder(View itemView) {
super(itemView);
context = itemView.getContext();
nameOfSlip = (TextView) itemView.findViewById(R.id.demoText);
slipImage = (ImageView) itemView.findViewById(R.id.imageViewDemoVideo);
}
public void bindSlip(VideoList videoList) {
nameOfSlip.setText(videoList.stringSlipName);
slipImage.setImageResource(videoList.stringImage);
}
}
class VideoList {
public String stringSlipName;
public int stringImage;
public VideoList(String stringSlipName, int stringImage) {
this.stringImage = stringImage;
this.stringSlipName = stringSlipName;
}
}
答案 0 :(得分:3)
您应该在点击项目的列表器中编写此代码
View view = inflater.inflate(R.layout.abc_card_view_video, parent, false);
samplelayout = (BlurLayout) parent.findViewById(R.id.blur_layout);
View hover = inflater.inflate(R.layout.hover_card_view, null);
samplelayout.setHoverView(hover);