# findViewById

**URL:** <https://discuss.kotlinlang.org/t/findviewbyid/10513>\
**Category:** Android\
**Created:** [November 25, 2018, 8:25am UTC](https://discuss.kotlinlang.org/t/findviewbyid/10513 "2018-11-25T08:25:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexandrandroiddev](https://avatars.discourse-cdn.com/v4/letter/a/c57346/32.png) [@alexandrandroiddev](https://discuss.kotlinlang.org/u/alexandrandroiddev)\
**Post date:** [November 25, 2018, 8:25am UTC](https://discuss.kotlinlang.org/t/findviewbyid/10513/1 "2018-11-25T08:25:52Z")

</div>

To assign a click listener to view, need to write  
findViewById\<View\>(R.id.resId).setOnClickListener(someClickListener)

If you write without describing generic as View  
findViewById(R.id.resId).setOnClickListener(someClickListener)  
you will recieve error message

```
Type inference failed: Not enough information to infer parameter T in 

fun <T : View!> findViewById(id: Int): T!
Please specify it explicitly.

```

But you need method setOnClickListener in View class. So it easy to parse T:View! as View

---

<div class="post-metadata">

**Author:** ![Alexey.Belkov](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/alexey.belkov/32/5215_2.png) [@Alexey.Belkov](https://discuss.kotlinlang.org/u/Alexey.Belkov)\
**Post date:** [November 27, 2018, 12:03pm UTC](https://discuss.kotlinlang.org/t/findviewbyid/10513/2 "2018-11-27T12:03:44Z")

</div>

Discussed here: [https://youtrack.jetbrains.com/issue/KT-28414](https://youtrack.jetbrains.com/issue/KT-28414)
