What is “View v” in the typical “onClick” call in Java?

avatar
12    10 months ago

In the generated code below, v is never referred to. What exactly does it represent in terms of the clicking and listening and subsequent action that occurs?

btnReturnToUI.setOnClickListener
       (new OnClickListener() 
       {
           public void onClick(View v) ///////////////////////////// 
           {
               MainActivity currentActivity = (MainActivity) getActivity();
               currentActivity.showUI();
           }
       }
);
Answers { 1 }
avatar
10 months ago

It's the thing you've clicked / set the listener on. In your example it's the same as btnReturnToUI.

One of the uses for this is to register the same listener on multiple buttons and then do different things in the listener depending on v or v.getId() which is the id in the xml layout e.g. @+id/the_id