如何将按钮属性提供给调用到 ArrayList 中的 ImageView?

问题描述

我创建了一个显示城市名称的 ArrayList,但是当我点击这个 ArrayList 中的图像时,我希望它重定向到不同的“活动”。我怎样才能做到这一点 ?我希望每个都重定向到不同的页面

`public class ParentRecyclerViewAdapter extends RecyclerView.Adapter { 私有ArrayList parentModelArrayList; 公共上下文cxt;

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 (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...