如何解决如何将按钮属性提供给调用到 ArrayList 中的 ImageView?
我创建了一个显示城市名称的 ArrayList,但是当我点击这个 ArrayList 中的图像时,我希望它重定向到不同的“活动”。我怎样才能做到这一点 ?我希望每个都重定向到不同的页面。
`public class ParentRecyclerViewAdapter extends RecyclerView.Adapter
public static class MyViewHolder extends RecyclerView.ViewHolder {
public TextView category;
public RecyclerView childRecyclerView;
public MyViewHolder(View itemView) {
super(itemView);
category = itemView.findViewById(R.id.Movie_category);
childRecyclerView = itemView.findViewById(R.id.Child_RV);
}
}
public ParentRecyclerViewAdapter(ArrayList<ParentModel> exampleList,Context context) {
this.parentModelArrayList = exampleList;
this.cxt = context;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent,int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.parent_recyclerview_items,parent,false);
return new MyViewHolder(view);
}
@Override
public int getItemCount() {
return parentModelArrayList.size();
}
@Override
public void onBindViewHolder(MyViewHolder holder,int position) {
ParentModel currentItem = parentModelArrayList.get(position);
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(cxt,LinearLayoutManager.HORIZONTAL,false);
holder.childRecyclerView.setLayoutManager(layoutManager);
holder.childRecyclerView.setHasFixedSize(true);
holder.category.setText(currentItem.movieCategory());
ArrayList<ChildModel> arrayList = new ArrayList<>();
if (parentModelArrayList.get(position).movieCategory().equals("France")) {
arrayList.add(new ChildModel(R.drawable.france_1,"Château de Chambord"));
arrayList.add(new ChildModel(R.drawable.france_2,"Nice"));
arrayList.add(new ChildModel( R.drawable.france_3,"Villefranche-Sur-Mer"));
arrayList.add(new ChildModel( R.drawable.france_4,"Mont Saint-Michel"));
arrayList.add(new ChildModel( R.drawable.france_5,"Paris"));
}
ChildRecyclerViewAdapter childRecyclerViewAdapter = new ChildRecyclerViewAdapter(arrayList,holder.childRecyclerView.getContext());
holder.childRecyclerView.setAdapter(childRecyclerViewAdapter);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。