How do I get the position selected in a RecyclerView?

前端 未结 13 2513
自闭症患者
自闭症患者 2020-11-27 04:40

I am experimenting with the support library\'s recyclerview and cards. I have a recyclerview of cards. Each card has an \'x\' icon at the top right corner to remove it:

13条回答
  •  我在风中等你
    2020-11-27 05:04

     public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    
        FrameLayout root;
    
    
        public ViewHolder(View itemView) {
            super(itemView);
    
            root = (FrameLayout) itemView.findViewById(R.id.root);
            root.setOnClickListener(this);
        }
    
    
        @Override
        public void onClick(View v) {
            LogUtils.errorLog("POS_CLICKED: ",""+getAdapterPosition());
        }
    }
    

提交回复
热议问题