gpt4 book ai didi

android - 在 recyclerview 中为项目设置悬停

转载 作者:搜寻专家 更新时间:2023-11-01 08:26:02 24 4
gpt4 key购买 nike

我有一个 ListView ,因为我有卡片 View 的回收 View ...当我选择其中任何一个时,应该会有一个 float 布局,其中有 3 个按钮。我正在使用这个库 enter link description here .

我在适配器中使用这个库并在 Activity 中设置了该适配器,但我一进入 Activity 应用程序就崩溃并出现 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;
}

}

最佳答案

您应该在项目的监听器或点击中编写此代码

 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);

关于android - 在 recyclerview 中为项目设置悬停,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44995529/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com