FindViewById & On Click Listener

In this tutorial you will learn about the FindViewById & On Click Listener and its application with practical example.

In Kotlin we do not need to fetch our component using Id, It depends upon you If you want to fetch them so you can. You can directly Access your xml component without using “findViewById()”.In this article we get know about On-click Listener and set text into component.
#Use of component without using “findViewByID()” So Now say good by to findViewById() and just write your logic with less verbosity.

#On-Click Listener: The below code will show you that how can you use On-click Listener, In Kotlin and in Java.

Table Of Contents

Kotlin:

Java:

Example:Let get more understand it by this simple example.

#Main Activity:the below code I have used in MainActivity.

Xml: The below xml is associated with MainActivity.

Output:So output of this code will look like below images. First Image when you will run this code and second when you will click on Button.

1

2

In this tutorial we have learn about the FindViewById & On Click Listener and its application with practical example. I hope you will like this tutorial.