Clicking on item programmatically in RecyclerView

后端 未结 4 887
闹比i
闹比i 2020-12-14 16:03

I am loading a list of categories and depending on which is selected, I need to show the products of the corresponding category in the RecyclerView. So when I f

4条回答
  •  轮回少年
    2020-12-14 16:31

    Without your code we don't know how you implement your onClickListener.

    Normally, you implement and set the item onClickListener in the viewHolder of your RecyclerView.Adapter.
    For example: ViewHolder.itemView.setOnClickListener(listener);

    So the solution is you can use recyclerView.findViewHolderForAdapterPosition(0).itemView.performClick()

    PS: Do not use findViewHolderForLayoutPosition() according to the Doc

提交回复
热议问题