Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Listener is is almost similar kind of delegate in dot net and may be objective C. Its main use is to hold the call back method when some action or event is performed. In the case of dotnet, we are passing the method itself as call back to the delegate (probably in Objective C, the case will be same.), but in java, there is no conscept like a delegate. So it is using the Interface to do the same trick.</p> <p>For example, If we need to assign a button click to a method, in dotnet and probably in objective C, we will be passing that function pointer to the corresponding click delegate. In Java, what we do is we will be creating an interface like this : </p> <pre><code>public interface ButtonClickListener{ void onClick(); } </code></pre> <p>Then inside the Button class, instead of delegate, we will be creating a function to accept this listener : </p> <pre><code>public void setOnClickListener(ButtonClickListener listener){ mButtonClickListener=listener; } </code></pre> <p>We will call this <code>setOnClickListener</code> method in our class with object of the <code>ButtonClickListener</code> implemented class.</p> <p>Then whenever the Button click happens, what the Button class do is : </p> <pre><code>mButtonClickListener.onClick(); </code></pre> <p>This will invoke the onClick of the <code>ButtonClickListener</code> Implemented class and we can perform the required operations over there.</p> <p>Handler is not related with this. This is an Android framework provided class to sync operations with the UI thread when we are working with other custom threads.</p> <p>Hope you got the idea!!.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload