// Touched
public class ChoiceTouchListener implements OnTouchListener {
public boolean onTouch(View view, MotionEvent motionEvent) {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_MOVE:
return true;
case MotionEvent.ACTION_DOWN:
Viewed = String.valueOf(view.getId());
ClipData data = ClipData.newPlainText("", "");
DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
// Drag Function When Item Touched
view.startDrag(data, shadowBuilder, view, 0);
return true;
case MotionEvent.ACTION_UP:
return true;
default:
return true;
}
}
}
private class ChoiceDragListener implements OnDragListener {
// onDrag Method, imagine we dragging numbers from display TextView
@Override
public boolean onDrag(View v, DragEvent event) {
// Android has onDrag action types. there are some kind of action
switch (event.getAction()) {
// if drag stared
case DragEvent.ACTION_DRAG_STARTED:
break;
// if drag entered software
case DragEvent.ACTION_DRAG_ENTERED:
break;
// if drag exited, stopped or something
case DragEvent.ACTION_DRAG_EXITED:
break;
// main case, if drag dropped what we do...
case DragEvent.ACTION_DROP:
// handle the dragged view being dropped over a drop view
View view = (View) event.getLocalState();
// stop displaying the view where it was before it was dragged
// ************* view.setVisibility(View.KEEP_SCREEN_ON);
// view dragged item, where numbers will be dragged
dropTarget = (TextView) v;
// view dropped item, that will be dropped in drag TextView
dropped = (TextView) view;
// view result place, when make math operation, show results
resultPlace = (TextView) findViewById(R.id.calcResult);
// simple debug
// ****** resultPlace.setText(dropped.getText() + " " + dropTarget.getText());
// if an item has already been dropped here, there will be a tag
Object tag = dropTarget.getTag();
// if there is already an item here, set it back visible in its
// original place
if (tag != null)
{
// the tag is the view id already dropped here
int existingID = (Integer) tag;
// set the original view visible again
findViewById(existingID).setVisibility(View.VISIBLE);
}
// set the tag in the target view being dropped on - to the ID
// of the view being dropped
dropTarget.setTag(dropped.getId());
// show results
resultPlace.setText(dropped.getText() + " " + dropTarget.getText() + " " + dropped.getText());
break;
// if drag ended, we did it already successfully
case DragEvent.ACTION_DRAG_ENDED:
break;
// what do default
default:
break;
}
return true;
}
}
매우 손쉬운 터치 및 드래그 클래스가 있습니다. 내 유일한 질문은 항목을 드래그하여 특정 레이아웃에 드롭하면 내 항목이 이전 위치에도 유지된다는 것입니다. 안드로이드에 감동적인 항목을 감지하고 삭제 한 후 삭제하는 방법이 있습니까?Android, 삭제 된 항목 삭제 후 삭제
대시 보드에서 숫자를 클릭하고 드래그 앤 드롭 한 다음 반복하여 대시 보드의 모든 항목을 X 및 Y 위치로 드래그합니다. 그게 내가 오래된 번호 공간을 비워서 다른 번호 공간을 만들려는 이유입니다.
감사합니다 ...
https://stackoverflow.com/questions/48293198/how-to-drag-and-drop-on-dropped-postion-and-deelete-item-from-draageview-in-andr @coreprojectz 해결책이 있으면 이 호에서 저를 제안 해주십시오. –