简体   繁体   English

水平和垂直 recyclerview 项目位置

[英]Horizontal and Vertical recyclerview item position

I have created horizontal recyclerview inside vertical recyclerview like google play store.我在垂直回收视图中创建了水平回收视图,如谷歌游戏商店。 am able to render items properly but when i add onclicklistener inside horizontal recyclerview am getting only horizontal item position, How to get veritcal recyclerview item position to get the clicked item completely from model class.?能够正确呈现项目,但是当我在水平 recyclerview 中添加 onclicklistener 时,我只能获得水平项目位置,如何获取 veritcal recyclerview 项目位置以完全从模型类中获取单击的项目。?

Suppose you have a List<Vertical> for outer recyclerView and a field of vertical list is List<Horizontal> for inner horizontal recyclerview Vertical object should be like this..假设您有一个List<Vertical>用于外部 recyclerView并且垂直列表的字段是List<Horizontal>用于内部水平 recyclerview垂直对象应该是这样的..

public class Vertical {

  //int vertical_Postion;
  List<Horizontal> horizontalList;


}

In recyclerAdapter Vertical (onBindViewHolder()) pass the position to the constructor like this..在 recyclerAdapter Vertical (onBindViewHolder()) 中,像这样将位置传递给构造函数..

   int vertical_position = position; // position you get in the onBindViewHolder
   RecylerAdapterHorizontal horizontal = new RecyclerAdapterHorizontal(context,horizontalList,vertical_postion);
   rv_horizontal.setAdapter(horizontal);

Now you can log the vertical postion in the reycler Adapter horizontal.. it will be constant for one horizontal list现在您可以在 reycler Adapter 中记录水平位置的垂直位置。对于一个水平列表,它将保持不变

Edit编辑

HorizontalAdapter(Context context,List<Horizontal> horizontal, int mVertPos)

 { 
       this.mVertPos = mVertPos;
       .......
   }  

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

        holder.yourView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Log.e("horizontal pos= " +position);
            Log.e("vert pos= " +mVertPos);

        }
    });



}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM