Drag and Drop

by Apoorva » Tue, 01 Jul 2008 16:40:59 GMT


Sponsored Links
 Can anyone suggest how to create drag and drop utility amongst the
views present on the screen?

--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by kaushik.siso » Fri, 09 Jan 2009 00:13:37 GMT


 hi

i want to know how can i enbale Drag and drop feature in android.
suppose i have a image,which are to be dragged and dropped on another
result and it will start a new activity.
i seek your help to  get a head-start atleast.

regards
k...@sis
--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


DRAG AND DROP

by kaushik sur » Fri, 09 Jan 2009 02:06:21 GMT


 hi

i got a suggestion here. but i really doubt whether it will work or not.



DRAG AND DROP

by Dianne Hackborn » Fri, 09 Jan 2009 02:23:26 GMT


 Sorry, there is no support for this currently built into the platform, you
will have to roll it yourself.  You shouldn't have trouble doing it yourself
for drag and drop in the same window (you can look at the standard home
screen for an example), but without system support doing it across windows
is much more challenging.






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.

--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by kaushik sur » Fri, 09 Jan 2009 02:34:14 GMT


 hi DIanne

thanks for ur suggestion. but suppose i want to do it on the same
widnow,then what will be the procedure.
trully speaking i am not getting any clue of that. i need prior info to
atleast check this feature on a single window

regards
kaushik






--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by Peli » Fri, 09 Jan 2009 03:12:40 GMT


 The code sample you linked to should work.

The basic idea is that you continuously put your image to a new
position according to the coordinates that you obtain through
ACTION_MOVE to give the illusion of dragging.
In ACTION_UP you check whether the finger position is close to the
target.
in ACTION_DOWN you can remember the initial finger coordinates so that
you can grab your icon everywhere correctly.

Basically you have to code everything by yourself, but it should not
be very difficult.

Peli
www.openintents.org



> not.



DRAG AND DROP

by Romain Guy » Fri, 09 Jan 2009 03:16:42 GMT


 You can also look at the source code of the Home (Launcher)
application, in particular the class called DragLayer.




>> not.



DRAG AND DROP

by Peli » Fri, 09 Jan 2009 05:09:27 GMT


 which can be found here:
 http://android.git.kernel.org/?p=platform/packages/apps/Launcher.git ;a=blob;f=src/com/android/launcher/DragLayer.java
with the related classes being here:
 http://android.git.kernel.org/?p=platform/packages/apps/Launcher.git ;a=tree;f=src/com/android/launcher

but this is the luxury version, including scaling of the image, scroll
zones, and vibration :-)

Peli





> >> not.



DRAG AND DROP

by kaushik sur » Fri, 09 Jan 2009 15:41:59 GMT


 i all

i have mentioned about a code link which can be used as an e.g. of the
Drag_N_Drop feature, but there will be small change.
the onMotionEvent(MotionEvent event) has to be replaced by
onTouchEvent(MotionEvent event).
though it starts the Drag_n_drop but it not smooth as u expect.
rather here i am getting a abnormal behavior,i.e, i am getting double image
of the button, that i drag and drop,Can anyone run the code sample and solve
the issue...?

regards
Kaushik

On Fri, Jan 9, 2009 at 2:39 AM, Peli <peli0...@googlemail.com> wrote:


--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by Peli » Fri, 09 Jan 2009 17:14:19 GMT


  don't know what your final code looks like that you use, but you can
change the visibility of the original item you are dragging
temporarily using setVisibility(View.INVISIBLE) or View.GONE depending
on how your layout is organized, so that only one item is visible
while dragging.

You could post your code here if you need further help.

Peli

On 9 Jan., 08:41, "kaushik sur" <kaushik....@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by Dan Raaka » Fri, 09 Jan 2009 18:02:03 GMT


 Refer Launcher code in the source tree.

-M




--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by kaushik sur » Fri, 09 Jan 2009 18:36:39 GMT


 i Peli

here i attach my code, to be added , i have ressolved the issue of double
image by getting rawX() value of the event , and setting my absolute layout
according to that.
but here i get a unique problem, whenever i click the button and try to drag
it, the mouse tip comes to a certain pixels above from the topleft corner of
the button,like a offset distance,if you run the code on the emulator u wil
find this problem.
can anyone help to solve this?


package com.google.android.samples.view.draganddrop;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent ;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.Toast;

public class Drag_And_Drop extends Activity {
/** Called when the activity is first created. */

@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);

MyView tx = new MyView(this);
tx.setText("Drag Me");
AbsoluteLayout l = new AbsoluteLayout(this);

AbsoluteLayout.LayoutParams p = new AbsoluteLayout.LayoutParams(
AbsoluteLayout.LayoutParams.WRAP_CONTENT,
AbsoluteLayout.LayoutParams.WRAP_CONTENT,10,10);
l.addView(tx,p);
setContentView(l);

}

class MyView extends Button
{
public MyView(Context c){
super(c);

}

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
int mCurX=(int)event.getRawX();
int mCurY=(int)event.getRawY();;
System.out.println("scrollx "+this.getScrollX());
int action = event.getAction();
if ( action == MotionEvent.ACTION_MOVE ) {
System.out.println("X="+mCurX+" y="+mCurY);
this.setText("x: " + mCurX + ",y: " + mCurY );
AbsoluteLayout.LayoutParams p = new
AbsoluteLayout.LayoutParams(AbsoluteLayout.LayoutParams.WRAP_CONTENT,
AbsoluteLayout.LayoutParams.WRAP_CONTENT,this.getScrollX()+ mCurX,
this.getScrollY()+mCurY);
this.setLayoutParams (p);

}
return true;
}

@Override
public void draw(Canvas canvas) {
// TODO Auto-generated method stub
super.draw(canvas);

}

}

}

#####main.xml#####

<?xml version=*"1.0"* encoding=*"utf-8"*?>

<LinearLayout xmlns:android=*"http://schemas.android.com/apk/res/android"
*

android:orientation=*"vertical"
*

android:layout_width=*"fill_parent"
*

android:layout_height=*"fill_parent"
*


<TextView

android:layout_width=*"fill_parent"*

android:layout_height=*"wrap_content"*

android:text=*"@string/hello"
*

/>

<Button

android:id=*"@+id/button"
*

android:layout_width=*"fill_parent"
*

android:layout_height=*"wrap_content"
*

android:text=*"start transfer"
*

/>

</LinearLayout>



regards
Kaushik

On Thu, Jan 8, 2009 at 11:23 PM, Dan Raaka <micromys...@gmail.com> wrote:


--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by Peli » Fri, 09 Jan 2009 20:53:03 GMT


 hat you have to do is, remember the coordinates that you get with the
ACTION_DOWN event.

Remember the distance (difference) between those coordinates and the
original coordinates of your image (call that offsetX and offsetY),
and subsequently in ACTION_MOVE always add those offset values.

Peli

On Jan 9, 11:36am, "kaushik sur" <kaushik....@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by kaushik sur » Fri, 09 Jan 2009 21:47:03 GMT


 i

Can you please illustrate the scenarios of the constants
ACTION_MOVE,ACTION_DOWN,ACTION_UP ?

regards
Kaushik

On Fri, Jan 9, 2009 at 6:22 PM, Peli <peli0...@googlemail.com> wrote:


--~--~---------~--~----~------------~-------~--~----~



DRAG AND DROP

by Peli » Fri, 09 Jan 2009 22:29:10 GMT


 ntroduce new member variables of your class:
int mOffsetX;
int mOffsetY;


Then below you do something like:

if ( action == MotionEvent.ACTION_DOWN ) {
System.out.println("X="+mCurX+" y="+mCurY);
this.setText("x: " + mCurX + ",y: " + mCurY );

mOffsetX = mCurX - 10; // 10 was the initial coordinate
mOffsetY = mCurY - 10;

} else if ( action == MotionEvent.ACTION_MOVE ) {
System.out.println("X="+mCurX+" y="+mCurY);
this.setText("x: " + mCurX + ",y: " + mCurY );
AbsoluteLayout.LayoutParams p = new
AbsoluteLayout.LayoutParams
(AbsoluteLayout.LayoutParams.WRAP_CONTENT,
AbsoluteLayout.LayoutParams.WRAP_CONTENT,this.getScrollX()+
mCurX + mOffsetX,
this.getScrollY()+mCurY + mOffsetY); //// Here you add the
offset values.
this.setLayoutParams (p);

}

I hope this helps as a pointer. Note that after you placed the object
to a new position, you have to remember the new coordinates (instead
of (10,10) where you started originally).

ACTION_DOWN is called when you click the mouse button, ACTION_MOVE is
called while you click and drag, and ACTION_UP is called when you
release the mouse button. Replace mouse by finger on the actual
device :-)

I hope this is what you meant.

Peli
www.openintents.org


On Jan 9, 2:46pm, "kaushik sur" <kaushik....@gmail.com> wrote:
--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. ROM Eclair Magic

Paging Magic defender.


ROM Eclair yang asik sekarang apa yah?
Udah coba Manup, tapi kena FC melulu waktu kirim sms (process.com.mms).
Sekarang lagi coba donlot KingClick.

Ada pilihan lain?
suhu @wongompong, gimana rekomendasinya? :D

Thanks,

Iwan

-- 
"Indonesian Android Community [id-android]" 

2. Example that prints 1 2 3 4 on A A A A?

I asked this question on Android Beginners several days ago, but didnt
get any nibbles. I have an app that almost works... I can draw the
needle on my gauge rotated, but I want to use A and Z keys to
increment and decrement the needle angle. I'd be gratefule if someone
could shoe me an example that catches the A key with onKeyDown,
increments a variable, and prints it out (drawText?). Thanks in
advance, fellow developers. I hope to be one soon.

-- 

3. programatically press a button

4. Popping up a custom Dialog from a Widget (AppWidget)

5. system hangs while giving Android build

6. Emulator Loading Error

7. Indosatm2 unlimited