问题描述
我创建了一个显示城市名称的 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 (将#修改为@)