I wonder how Android OnClik Listener works? What Pattern is it? Observer?
I cant imagine how I can Implement it in my App! It needs to be a custom implementation because I want to do it with my Objects not with views.
So how can I achieve to call obj.setOnClickListener(new Class(){});
in my code?
I mean ok I could have a methode in my baseclass from which the derived classes implement and then just havin a static ArrayList or so. But how can I add new Classes to this List at runtime?
The definiton of this class OnClickListener(){} is strange.
How is it possible to define an existing class and overriding a method?
My Java is not that good never done this...
EDIT: THIS QUESTION IS NOT ABOUT HOW TO USE ONCLICKLISTENER. I KNOW HOW TO USE THAT...
What i want:
I want a Super Class having an implementation of a method like this:
public void setMyOnclickListener(MyOnClickListener myListener)
{
//magic code
}
and now I want to have an Object of this class lets call it
Subclass obj;
and now I want to do this:
obj.setMyOnClickLister(new MyOnClickListener()
{
//defined method at runtime
public void aDefinedMethod()
{
//here goes in some code
}
});
how can I have a method with a class as a parameter which only exist as an anonymous class?
EDIT2:
Ok I get it OnClickListener is just an Interface -.- not a class defintion That was my confusion!!!