Android recyclerView findViewHolderForAdapterPosition returns null

后端 未结 6 1130
醉梦人生
醉梦人生 2020-11-27 07:08

I want to click an item in recyclerView programmatically, I found a way do that:

recyclerView.findViewHolderForAdapterPosition(0).itemView.performClick();
         


        
6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-27 07:53

    I wouldnt recommend using post delay. Although it works the timing is arbitrary.

    Using OnPreDrawListener on the recyclerview, timing will be aligned with the next draw cycle and visible items are accessible.

提交回复
热议问题