我正在使用一个库悬停在recylerview的项目上,但是项目的列表器工作之前没有工作,问题是 - 在另一个膨胀的xml文件上膨胀新的xml文件的正确方法是什么?
提前致谢。
public class LessonVideoAdapter extends RecyclerView.Adapter<LessonVideoAdapter.LessonDataHolder> {
private List<VideoList> slipList;
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));
slipList.add(new VideoList("Chapter 4", R.drawable.demo_two));
}
@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();
}
public class LessonDataHolder extends RecyclerView.ViewHolder {
public BlurLayout samplelayout;
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);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
{
Log.d("ashu", " clicked " + getAdapterPosition());
}
}
});
}
public void bindSlip(VideoList videoList) {
nameOfSlip.setText(videoList.stringSlipName);
slipImage.setImageResource(videoList.stringImage);
}
}
public class VideoList {
public String stringSlipName;
public int stringImage;
public VideoList(String stringSlipName, int stringImage) {
this.stringImage = stringImage;
this.stringSlipName = stringSlipName;
}
}
}
答案 0 :(得分:1)
如果没有看到你的xml并根据我的理解,我会建议试试这个 -
onCreateViewHolder()替换为此
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.abc_card_view_video, parent, false);
return new LessonDataHolder(v);
在itemView.setOnClickListener()之前将它放在 -
之前itemView.setClickable(true);
我不确定正确的方法来膨胀xml但是我正在使用下面的代码来扩展xml我需要的地方除了recyclerView适配器onCreateViewHolder()方法回调 -
View view = getLayoutInflater(null).inflate(R.layout.scanner_manual_entry, null);
如果这样可以解决您的问题,请将此帖标记为答案 希望这有帮助