I have a main activity with custom canvas:
public void onCreate(Bundle savedInstanceState) {
...
CustomCanvas c = new CustomCanvas(this);
c.requestFocus();
cll = (LinearLayout)findViewById(R.id.CLL);
cll.addView(c);
}
public void qwerty(String w) {
....
TextView abc = (TextView)findViewById(R.id.TextViewabc);
abc.setText(w);
....
}
Inside CustomCanvas, I have a GestureDetector with SimpleOnGestureListener.
I want to call qwerty() from the methods of SimpleOnGestureListener (such as onSingleTapConfirmed)
Is this possible? If not is there another way of doing so?
Thanks
….EDIT….. (more info)
GestureDetector is an object in my CustomCanvas
public class CustomCanvas extends View {
GestureDetector gd;
...
public CustomCanvas(final Context context) {
super(context);
gd = new GestureDetector(getContext(), new SimpleOnGestureListener() {
....
// I also use getScrollX() and getScrollY() in some of the methods here
});
}
....
@Override
public boolean onTouchEvent(MotionEvent ev) {
return gd.onTouchEvent(ev);
}
}
You got two options. Either you implement the SimpleOnGestureListener in the Activity and set it to the CustomCanvas or you pass the Activity to the CustomCanavas so you can call qwerty() on it from the listener inside the CustomCanvas class.
UPDATE
In you Activity class you have to pass the activity to the CustomCanvas.