0
在我的應用程序中,有3個圖像被拖放到3個佈局中。如何在「DragListener完成後顯示Toast」
我試圖展示一個吐司之後,他們三人已經下降到他們的適當位置。
目前,在麪包後會出現他們的每一個一個
這是到目前爲止我的代碼
@Override
public boolean onDrag(View v, DragEvent e) {
int action = e.getAction();
View view = (View) e.getLocalState();
switch (action) {
case DragEvent.ACTION_DRAG_STARTED:
return true;
case DragEvent.ACTION_DRAG_ENTERED:
return false;
case DragEvent.ACTION_DRAG_EXITED:
Toast.makeText(getActivity(), "Finished", Toast.LENGTH_SHORT).show();
// return false;
case DragEvent.ACTION_DROP:
if (view.getId() == R.id.topPiece && v.getId() == R.id.topContainer) {
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
LinearLayout container = (LinearLayout) v;
container.addView(view);
view.setVisibility(View.VISIBLE);
view.setOnTouchListener(null);
view.setOnDragListener(null);
}
if (view.getId() == R.id.middlePiece
&& v.getId() == R.id.middleContainer) {
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
LinearLayout container = (LinearLayout) v;
container.addView(view);
view.setVisibility(View.VISIBLE);
view.setOnTouchListener(null);
view.setOnDragListener(null);
}
if (view.getId() == R.id.bottomPiece
&& v.getId() == R.id.bottomContainer) {
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
LinearLayout container = (LinearLayout) v;
container.addView(view);
view.setVisibility(View.VISIBLE);
view.setOnTouchListener(null);
view.setOnDragListener(null);
}
case DragEvent.ACTION_DRAG_ENDED:
if (dropEventNotHandled(e)) {
view.setVisibility(View.VISIBLE);
}
}
return false;
}
private boolean dropEventNotHandled(DragEvent e) {
// TODO Auto-generated method stub
return !e.getResult();
}