sorry if this question is stupid, but I can’t wrap my head around Java syntax..I learnt C/C++
I know View is a class which is good..but I don’t understand if View.OnClickListener() is a method.
I doubt it unless it returns an object?
I think View is a class which has a static OnClickListener member object..again that doesn’t make sense to me..
Can some explain what is happening with this line of code?
button1 = (Button) findByView(R.id.button1) ;
button1.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
}
}
So what is happening with this code?
Button1 is a reference to the button1 object in the xml file.
button1 object has a member object setOnClickListener which I from its name I assume initializes an event to the button or something. But it receives View.OnClicListener() object.
I am confused by that..onClick receives a View object so onClickListener is not an object returns a View object?? I don’t get it at all.
Can someone explain what happens in that line View.onClickListener() is it another way of saying new this?
View.OnClickListeneris an interface, you don’t call it, but creates a new instance of it (new View.OnClickListener()is a call to the constructor)The instance you create is of anonymous class that
implementsView.OnClickListener, in the brackets right undernew View.OnClickListener()Any class that implements
View.OnClickListenermust implement the methods declared in it (e.g. onClick)setOnClickListenerjust saves the reference to the View.OnClickListener instance you supplied, and when someone clicks the button, theonClickmethod of the listener you set is getting called.