I have extended the android View class, and now I want to define a method in the view that launches when the view is longClicked.
I already have actions for the motionevents using public boolean onTouchEvent(MotionEvent event). This method doesn’t allow for long clicks to take action upon.
I want to do it in the extended View class itself. I’m aware that I can add an OnLongClickListener to the view in the activity, but I’d like to know if there’s a way to implement this in the View itself.
public class ArchitectureView extends GraphView implements OnLongClickListener {
public ArchitectureView(Context context) {
super(context);
this.setOnLongClickListener(this);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_CANCEL:
break;
}
return true;
}
@Override
public boolean onLongClick(View v) {
Log.e("I've been", "longclicked");
return false;
}
}
GraphView is extended from View and also overrides onTouchEvent and calles super
can you post your onTouchEvent() Method?
I think you’ll have to implement the parameters for the longpress as logic inside your that touch event callback.
In order to do so you’d have to test for the “pattern” of a longpress
something like if(ACTION_UP_TIME < (ACTION_DOWN_TIME + someMillis))
EDIT: Upon thinking about it more, couldn’t you just implement OnLongClickListener on your view object, then override the onLongClick() Callback?
Like this: