Thursday, July 28, 2011

Android onClickListener

Today I want to talk about Android onClickListener. Android has three way to implement onClick Listener.

First way:
You should create Activity class with implementation onClickListener interface. And override onClick method. Create button object and set parameter setOnClickListenr(this);



Result:


Second way:
Create an anonymous event handler class and override onClick method inside it.

Result:

Third way:
Declare a function public void anyName(View v)  and handle a button click.


In the xml file, specify the value of the button onClick.


Enter the function name that you declare.


Result: