---
# System prepended metadata

title: Programmatically click in recyclerview
tags: [實作相關]

---

Programmatically click in recyclerview
===

目的是想要進入畫面預設就點擊第一個 `recyclerview` 的 `item`，目前只看到此 workarround 方法，先採用。
注意 `delay` 若設太短，一樣有機率會發生 `recyclerView.findViewHolderForAdapterPosition(0) `回傳
 `null` 的情況。

```java=
new Handler().postDelayed(new Runnable() {
    @Override
    public void run() {
      recyclerView.findViewHolderForAdapterPosition(position).itemView.performClick();

    }
}, 100);

```

## Ref.
[Clicking on item programmatically in RecyclerView](https://stackoverflow.com/questions/29745919/clicking-on-item-programmatically-in-recyclerview)

###### tags: `實作相關`