Reputation: 5163
I am little bit confused regarding backend working of anonymous class, like if we have a button and we are setting onclickListener
Button B = (Button)findViewById(R.id.myButton);
B.setOnClickListener(new onClickListener(){
public void onClick(View V){
Log.v("","Hello world");
}
));
What is here actually happening in backend ?Does this will implement interface of View.OnClickListener or something else???
Upvotes: 0
Views: 1150
Reputation: 83303
Anonymous classes must always extend a class or implement an interface.
b.setOnClickListener(new OnClickListener() {
public void onClick(View V) {
Log.v("", "Hello world");
}
});
In this case, you are creating a new anonymous (unnamed) class that implements the View.OnClickListener
interface. This works because the setOnClickListener
method takes an argument of type View.OnClickListener
.
Upvotes: 1
Reputation: 7044
Yes it is an instance of new unnamed class that implements the OnClickListener interface.
Upvotes: 2
Reputation: 15701
Please look over this
How can an anonymous class use "extends" or "implements"?
http://docstore.mik.ua/orelly/java-ent/jnut/ch03_12.htm
Upvotes: 2