Android : Drag and drop buttons in android

on Sunday, August 17, 2014


I have some problems i dont want to add buttons on the end of colums: At the moment it work like that: if i have got 5 buttons: 1,2,3,4,5: i want to button 2 drag on position betwen button 4 and 5 1 3 4 2 5 but it is drag 1 3 4 5 2 But i dont know why. And second problem is if drag the button on the unlayer surface it and there drop it will be desapiard but i dont know where ?


And second question is how can i save position of buttons and use it for another itent



class MyDragListener implements OnDragListener {
Drawable enterShape = getResources().getDrawable(R.drawable.shape_droptarget);
Drawable normalShape = getResources().getDrawable(R.drawable.shape);

@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:
v.setBackgroundDrawable(enterShape);
break;
case DragEvent.ACTION_DRAG_EXITED:
v.setBackgroundDrawable(normalShape);
break;
case DragEvent.ACTION_DROP:
// Dropped, reassign View to ViewGroup
View view = (View) event.getLocalState();
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
LinearLayout container = (LinearLayout) v;
container.addView(view);
// container.

view.setVisibility(View.VISIBLE);
break;
case DragEvent.ACTION_DRAG_ENDED:
v.setBackgroundDrawable(normalShape);
default:
break;
}
return true;
}
}

0 comments:

Post a Comment