猿问

如何制作“查看所有项目”按钮将数据从 RecyclerView 传递到另

问题_

我想让"See All Item"按钮将数据从 RecyclerView 传递到另一个 RecyclerView 片段,它看起来像游戏商店,有按钮"More"可以查看另一个片段中的所有项目

AdapterSingleHotTrendingNews.java


public class AdapterSingleHotTrendingNews extends RecyclerView.Adapter{


private Context mContext;

private ArrayList<ModelSingleHotTrendingNews> modelSingleHotTrendingNews;


public AdapterSingleHotTrendingNews(Context mContext, ArrayList<ModelSingleHotTrendingNews> modelSingleHotTrendingNews) {

    this.mContext = mContext;

    this.modelSingleHotTrendingNews = modelSingleHotTrendingNews;

}


//Container

@Override

public SingleHotTrendingNewsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {

    View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_single_hottrendingnews, null);

    return new SingleHotTrendingNewsViewHolder(v);

}


//Fill Container with Model Setter Getter

@Override

public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {


    final SingleHotTrendingNewsViewHolder singleHotTrendingNewsViewHolder = (SingleHotTrendingNewsViewHolder) holder;

    final ModelSingleHotTrendingNews modelSingleHotTrendingNewsX = modelSingleHotTrendingNews.get(position);


    //Set

    singleHotTrendingNewsViewHolder.TVGameDate.setText(modelSingleHotTrendingNewsX.getGamedate());

    singleHotTrendingNewsViewHolder.TVGameDescription.setText(modelSingleHotTrendingNewsX.getGamedescription());

    singleHotTrendingNewsViewHolder.IMGGameImage.setImageResource(modelSingleHotTrendingNewsX.getGameimage());



茅侃侃
浏览 95回答 2
2回答

斯蒂芬大帝

从第一个适配器onClick,调用第二个适配器并更新 RecyclerViewsectionHotTrendingNewsViewHolder.BTNHotTrendingNewsMore.setOnClickListener(new View.OnClickListener() {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public void onClick(View v) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sectionHotTrendingNewsViewHolder.RecyclerViewSectionHotTrendingNews.setAdapter( new AdapterSingleHotTrendingNews(v.getContext(), modelSectionHotTrendingNews.get(position).getAllItemsInSection()))&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; });或者,如果您想在其他活动中显示此更多新闻。然后执行以下操作:像这样创建ModelSingleHotTrendingNews类:Serializable公共类 ModelSingleHotTrendingNews 实现 Serialized { ... }改变onClicksectionHotTrendingNewsViewHolder.BTNHotTrendingNewsMore.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent Intent = new Intent(mContext, TabMoreHotActivity.class); Intent().putExtra("MoreNews", modelSectionHotTrendingNews.get(位置).getAllItemsInSection()) mContext.startActivity(intent); } });TabMoreHotActivity使用 ArrayList 而不是ArrayList<ModelSectionHotTrendingNews>希望对你有帮助。你把你的代码弄乱了:(

犯罪嫌疑人X

您可以在 Recyclers 父级中创建侦听器。当一个回收器的某些数据发生更改时,在您的父级接收到它后触发当前适配器中的侦听器,并将触发第二个回收器适配器中的某些更新方法。但如果您提供一些代码或更详细的描述,肯定会更好。
随时随地看视频慕课网APP

相关分类

Java
我要回答