This must be a noob question, but I can't find the proper wait to achieve the following:
In android, I made a subclass MyView extending a View class. In B, I've defined a method mMethod not present in the View class.
Now, I want to set an OnClickListener interface on MyView. Doing this, I must override a onClick method when defining a new OnClickListener. Furthermore, I would like to access the mMethod method in onClick, but the overriden method is expecting a View class instance, not a MyView's one. So what can I do ?
To be more precise:
public class MyView extends View{
...
public void mMethod(){
...
}
}
And in the main class (Activity)
MyView myView = new MyView ()
//It's not the correct constructor, but it's not the point
myView.setOnClickListener(new OnClickListener(){
@Override
public boolean onClick(View v){
//Here I would like to access mMethod of MyView
???
}
}
Is using myView.mMethod()
is the only solution ? Is it possible to downcast v
to (MyView)v
? If so, how to do it ? Should I define a sub-interface ?
Thank you!