Java 如何检测ondraglistener是否已完成?(安卓)
我需要在使用stopSelf()激活侦听器后停止此服务;但是,即使没有拖动事件,服务也会结束。。。在调用StopService之前,如何检测是否发生了拖动事件Java 如何检测ondraglistener是否已完成?(安卓),java,android,listener,gravity,Java,Android,Listener,Gravity,我需要在使用stopSelf()激活侦听器后停止此服务;但是,即使没有拖动事件,服务也会结束。。。在调用StopService之前,如何检测是否发生了拖动事件 mainButton.setOnTouchListener(new MyTouchListener()); vTopLeft.setOnDragListener(new MyDragListener()); vTopRight.setOnDragListener(new M
mainButton.setOnTouchListener(new MyTouchListener());
vTopLeft.setOnDragListener(new MyDragListener());
vTopRight.setOnDragListener(new MyDragListener());
vBottomLeft.setOnDragListener(new MyDragListener());
vBottomRight.setOnDragListener(new MyDragListener());
Log.d("tok", "add mview");
stopSelf(); ---> this should wait after draglistener is finish.
MyDragListener.java
Public class MyDragListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
String containerName = null;
int ID = 0;
int Dragaction = event.getAction();
int gravity2 = 1234567879;
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
owner.setVisibility(View.GONE);
FrameLayout container = (FrameLayout) v;
container.addView(view);
LocationSerializable ls = new LocationSerializable();
switch (v.getId()) {
case R.id.topLeft:
gravity2 = Gravity.LEFT | Gravity.TOP;
ls.setGravity(gravity2);
break;
case R.id.topRight:
gravity2 = Gravity.RIGHT | Gravity.TOP;
ls.setGravity(gravity2);
break;
case R.id.bottomLeft:
gravity2= Gravity.BOTTOM | Gravity.LEFT;
ls.setGravity(gravity2);
break;
case R.id.bottomRight:
gravity2 = Gravity.RIGHT | Gravity.BOTTOM;
ls.setGravity(gravity2);
break;
default:
throw new RuntimeException("Unknown ID");
}
LinearLayout containerParent = (LinearLayout) v.getParent();
LinearLayout conatainerGrandMother = (LinearLayout) containerParent.getParent();
conatainerGrandMother.setVisibility(View.GONE);
case DragEvent.ACTION_DRAG_ENDED:
default:
break;
}
return false;
}
}
在案例拖动事件中停止服务。操作拖动结束: 下面是一个示例模板
@Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
// Dropped, reassign View to ViewGroup
break;
case DragEvent.ACTION_DRAG_ENDED:
// option 1
Context.stopService();
// option 2
// stopService(new Intent(Activity.this,MailService.class));
//stopSelf();
// other alternative is
// v.getContext().stopService(new Intent(v.getContext(),DragDropButtonMainService.class));
break;
}
return true;
}
据
用户释放拖曳阴影后,系统发出(如有必要)动作类型为action\u DROP的拖曳事件后,系统发出动作类型为action\u drag\u ENDED的拖曳事件,以指示拖曳操作结束
在案例拖动事件中停止服务。操作拖动结束: 下面是一个示例模板
@Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (event.getAction()) {
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
case DragEvent.ACTION_DRAG_ENTERED:
break;
case DragEvent.ACTION_DRAG_EXITED:
break;
case DragEvent.ACTION_DROP:
// Dropped, reassign View to ViewGroup
break;
case DragEvent.ACTION_DRAG_ENDED:
// option 1
Context.stopService();
// option 2
// stopService(new Intent(Activity.this,MailService.class));
//stopSelf();
// other alternative is
// v.getContext().stopService(new Intent(v.getContext(),DragDropButtonMainService.class));
break;
}
return true;
}
据
用户释放拖曳阴影后,系统发出(如有必要)动作类型为action\u DROP的拖曳事件后,系统发出动作类型为action\u drag\u ENDED的拖曳事件,以指示拖曳操作结束
谢谢你,但我的MydAglistener()中没有止步符。我会把代码贴在这里。。它只实现view.ondraglistener。我的要求是在操作\u拖放\u结束期间,我需要停止我的服务。。。您的答案很好,但在MyDragListener中找不到stopself()。在MyDragListener中找不到stopself()。我不明白此>您是否无法调用此方法?是。。。MyDragListener中没有stopself方法,因为它不扩展服务@布朗托克耶斯。。。stopself()只能在服务内部使用。我想的是在mydraglistener类中有一个stopself(),或者如果它们是一种知道侦听器是否已经完成的方法,那么就在服务本身上使用stopself()。谢谢,但是mydraglistener()中没有stopself()。我会把代码贴在这里。。它只实现view.ondraglistener。我的要求是在操作\u拖放\u结束期间,我需要停止我的服务。。。您的答案很好,但在MyDragListener中找不到stopself()。在MyDragListener中找不到stopself()。我不明白此>您是否无法调用此方法?是。。。MyDragListener中没有stopself方法,因为它不扩展服务@布朗托克耶斯。。。stopself()只能在服务内部使用。我想的是在mydraglistener类中有一个stopself(),或者如果它们是一种知道侦听器是否已经完成的方法,那么就在服务本身上有一个stopself()。