Cómo arrastrar un elemento de un listview y dejarlo en un textView exterior?

Estoy tratando de implementar un ejemplo de arrastrar y soltar de android. Después de presionar un ítem largo, lo estoy arrastrando hasta un nivel objetivo y cayendo ahí. Tengo éxito de alguna manera. Pero quiero algo diferente. He hecho algo como esto Introduzca aquí la descripción de la imagen

Pero quiero agregar todos los elementos a una lista y voy a pic de un elemento después de presionar largo en listview, entonces voy a arrastrar el elemento a mi nivel de destino y dejarlo allí. Quiero algo como esto Introduzca aquí la descripción de la imagen

Mi código se da a continuación …

public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.mango).setOnLongClickListener(longListen); findViewById(R.id.orange).setOnLongClickListener(longListen); findViewById(R.id.apple).setOnLongClickListener(longListen); findViewById(R.id.banana).setOnLongClickListener(longListen); findViewById(R.id.drop_here).setOnDragListener(DropListener); listview.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int pos, long id) { // TODO Auto-generated method stub Log.i("long clicked","pos"+" "+pos); return true; } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } OnLongClickListener longListen = new OnLongClickListener() { @Override public boolean onLongClick(View v) { DragShadow dragShadow = new DragShadow(v); ClipData data = ClipData.newPlainText("", ""); v.startDrag(data, dragShadow, v, 0); return false; } }; private class DragShadow extends View.DragShadowBuilder { ColorDrawable greyBox; public DragShadow(View view) { super(view); // TODO Auto-generated constructor stub greyBox = new ColorDrawable(Color.LTGRAY); } @Override public void onDrawShadow(Canvas canvas) { // TODO Auto-generated method stub // super.onDrawShadow(canvas); greyBox.draw(canvas); } @Override public void onProvideShadowMetrics(Point shadowSize, Point shadowTouchPoint) { // TODO Auto-generated method stub // super.onProvideShadowMetrics(shadowSize, shadowTouchPoint); View v = getView(); int height = (int) v.getHeight() / 2; int width = (int) v.getWidth() / 2; greyBox.setBounds(0, 0, width, height); shadowSize.set(width, height); shadowTouchPoint.set(width / 2, height / 2); } } OnDragListener DropListener = new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { // TODO Auto-generated method stub int dragEvent = event.getAction(); switch (dragEvent) { case DragEvent.ACTION_DRAG_ENTERED: Log.i("Drag ", "Entered"); break; case DragEvent.ACTION_DRAG_EXITED: Log.i("Drag ", "Exit"); break; case DragEvent.ACTION_DROP: Log.i("Drag ", "Drop"); TextView target = (TextView) v; TextView dragg = (TextView) event.getLocalState(); target.setText(dragg.getText()); break; default: break; } return true; } }; } 

He intentado algunos tutoriales, pero no puedo conseguir la solución de allí. Lista de Android Ver Arrastrar y soltar ordenar

He encontrado la solución. Es fácil, solo tienes que llamar al método startDrag dentro de setOnItemClickListener.

 listview.setOnItemLongClickListener(new OnItemLongClickListener() { public boolean onItemLongClick(AdapterView<?> arg0, View v, int pos, long id) { // TODO Auto-generated method stub v.startDrag(data, dragShadow, v, 0); return true; } }); 

Hay buen tutorial aquí http://www.vogella.com/articles/AndroidDragAndDrop/article.html por Lars Vogel. Pero funcionará sólo desde Android 4 y superior (después de ICS).

Si eso no te da una solución, trata de agregar un simple onTouchListener para arrastrar un objeto y ver si el objeto mientras arrastra cae dentro de los límites de la Vista en la que quieres arrastrar (una textview en tu caso)

Una sencilla implementación de Drag ontouchlistener se puede encontrar aquí: https://stackoverflow.com/a/9398861/2138983

  • Cómo obtener las coordenadas X, Y correctas de un DragEvent.ACTION_DROP
  • Agregar vista dinámica mediante WindowManager.addView
  • Cómo obtener el punto de intersección de Dos líneas (ImageViews)
  • Tamaño androide de la sombra del dragshadowbuilder
  • Arrastrar y soltar la clasificación de adaptador de cursor y adaptador de lista
  • La mejor manera de reordenar elementos en Android 4 + ListView
  • ¿Cómo restringir el arrastrar y soltar a lo largo del eje y sólo en android?
  • Arrastrar y soltar en android 3.x causa illegalStateException después de pequeño número en arrastra
  • Cómo hacer Drag & Drop Button en Android
  • OnDragListener no recibe DRAG_STARTED o DRAG_ENDED, pero obtiene ACTION_DROP
  • OnDragListener - ¿hay alguna biblioteca de compatibilidad para niveles de Android <11?
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.