1

stopSelf(); を使用してリスナーが既にアクティブ化された後、このサービスを停止する必要があります。ただし、Drag イベントがなくてもサービスは終了します... StopService を呼び出す前に Drag イベントが発生したかどうかを検出するにはどうすればよいですか?

           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;
    }
}
4

1 に答える 1