I am new to android development and I realized it's much more harder to use all the interfaces in a real world examples than using them in just sample codes which are trying to show you how to use the interface.
Since I would like to understand every single line I type I will start with this :
Button clearButton = (Button) findViewById(R.id.buttonClear);
clearButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
The first line is easy, I just assign a button to button object based on its id from xml but the listener I don't understand, simply I get the clearButton object and I will use one of its method, setOnClickListener
, and then in the argument I pass anonymous class which behavior I would like to override, but View.OnClickListener()
is method not an object so? I'm writing a class inside a function?
new View.OnClickListener() {
@Override
public void onClick(View v) {
}
this looks like it's a function OnClickListener
which contains a inline class so ?