如何在vertical recyclerview android中实现Vertical Recyclerview?

时间:2017-08-25 07:46:38

标签: android android-recyclerview

假设我在RecyclerView中有 2个项目,其中每个项目都有一个innerrecyclerview,其中 100个项目,它们都是垂直的或任何对现有问题没有任何影响的事情。

我已经在其他stackoverflow问题或其他Android博客上实现了此方法,但没有帮助。

我有一个关于onbindviewholder的问题,项目1内部RecyclerView的{​​{1}}被调用所有元素,即。 100 同时它们不是回收或任何东西,因为onbindviewholder没有调用滚动,这应该是正常行为onbindviewholder

如何使RecyclerView回收也是如此,因为所有其他帖子都没有谈到这一点。

CourseRVAdapter或ParentAdapter

innerrecyclerview

Horizo​​ntalRVAdapter或Inneradapter

public class CourseRVAdapter extends RecyclerView.Adapter<CourseRVAdapter.SimpleViewHolder> {

        private Context mContext;
        private List<data> merchantlist;
        private List<data> merchantlist2;
        private RecyclerView horizontalList;
        Typeface MRR;
        private Typeface MR;


        public class SimpleViewHolder extends RecyclerView.ViewHolder {
            public final TextView title;
            private HorizontalRVAdapter horizontalAdapter;

            public SimpleViewHolder(View view) {
                super(view);
                Context context = itemView.getContext();
                title = (TextView) view.findViewById(R.id.text_1);
                horizontalList = (RecyclerView) itemView.findViewById(R.id.my_recycler_view);
                horizontalList.setLayoutManager(new CustomLinearLayoutManager(mContext, 3));
                horizontalAdapter = new HorizontalRVAdapter(merchantlist, mContext, MR);
                horizontalList.setAdapter(horizontalAdapter);
            }
        }



        CourseRVAdapter(List<data> merchantlist2, Context mContext, Typeface MRR, List<data> merchantlist, Typeface MR) {

            this.merchantlist2 = merchantlist2;
            this.merchantlist = merchantlist;
            this.mContext = mContext;
            this.MRR = MRR;
            this.MR = MR;

        }
        public SimpleViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            final View view = LayoutInflater.from(mContext).inflate(R.layout.merchant_list_header, parent, false);
            return new SimpleViewHolder(view);
        }

        @Override
        public void onBindViewHolder(SimpleViewHolder holder, final int position) {



        }

        @Override
        public int getItemCount() {

            return merchantlist2.size();
        }

    }

我还没有添加如何为public class HorizontalRVAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { List<data> merchantlist; FragmentActivity main; Context mContext; Typeface MRR; public HorizontalRVAdapter(List<data> merchantlist, Context mContext, Typeface MRR) { this.merchantlist = merchantlist; this.mContext = mContext; this.MRR = MRR; } private class ItemViewHolder extends RecyclerView.ViewHolder { private TextView merchantname; public ItemViewHolder(View itemView) { super(itemView); merchantname = (TextView) itemView.findViewById(R.id.merchant_name); } } @Override public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { Context context = parent.getContext(); View itemView = LayoutInflater.from(context).inflate(R.layout.merchant_list_item, parent, false); ItemViewHolder holder = new ItemViewHolder(itemView); return holder; } @Override public void onBindViewHolder(RecyclerView.ViewHolder rawHolder, int position) { ItemViewHolder holder = (ItemViewHolder) rawHolder; data list = merchantlist.get(position); holder.merchantname.setText(list.merchantname); holder.itemView.setTag(position); Log.d("TAG", "onbindviewholder -- > " + position); } @Override public int getItemCount() { return merchantlist.size(); } } 填充数据。

例如recyclerview有1件或2件商品,parentrecyclerview有100件商品。

编辑:

所以在收到第一条评论后,我正在更新我希望获得更好的回应。

我有两个textview和一个Gridrecyclerview,我希望滚动gridrecyclerview时滚动两个textview。我想到了这样做的想法,为这两个文本视图和Griditems的简单项目持有者定义标题。

然后我必须设置带有跨度的Gridlayoutmanager,但它也包括前两个文本,我最终得到了该网格中的两个文本视图,这是不需要的。 The blue one is the one item of the oarentrecyclerview and the icon and text are the item for insiderecyclerview i want them to scroll in cohesion

1 个答案:

答案 0 :(得分:1)

问题在于另一个VERTICAL RecyclerView中的VERTICAL RecyclerView。在滚动嵌套的onBindView()项时,OP的问题是RecyclerView未被调用。

原因很简单:嵌套的RecyclerView正在绘制它的所有内容 视图,因为它的父级RecyclerView具有无限可用空间。

通过使用带有span查找的GridLayoutManager来解决OP的问题(有关详细信息,请参阅此SO answer),这样就无需使用嵌套RecyclerView