Android passing data on drag

What is the full-proof way of passing data with drag and drop?

In my situation I have two lists and i can drag element from one to another. So the list from which we drag already has data associated with it. From what I have searched the usual way is storing data by views setTag() and getTag() methods. This is also what I would do, but since both lists use view-holder pattern, the actual data would be stored in holder. And the holder would then be set as views tag. However I have also heard that you should never store data in views or in holder (im using view-holder pattern in list adapters).

So what would be the best way to pass data from one list to another?

Answers


Try to store data in root activity or fragment:

public class MyActivity extends Activity
        {
            private ListView list1;
            private ListView list2;
            private int dragPosition;


    ...
        protected class myDragEventListener implements View.OnDragListener {

        // This is the method that the system calls when it dispatches a drag event to the
        // listener.
        public boolean onDrag(View v, DragEvent event) {

            // Defines a variable to store the action type for the incoming event
            final int action = event.getAction();

            // Handles each of the expected events
            switch(action) 
            {

                case DragEvent.ACTION_DRAG_STARTED:
                    // save the position in one list
                    dragPosition = somePosition;
                        return true;

                case DragEvent.ACTION_DROP:

                    //do what you want with other list
                    return true;
            }
        }
    }

maybe, this will be helpful.


Need Your Help

Why should I learn C#?

c# java

I want to know why I should learn C#?

Missing Back Button from UIViewController in a Navigation Controller

ios objective-c uitableview uinavigationcontroller back

I have a tabbed table view controller and in one of the tabs, I'm clicking on a cell which takes me to a View Controller instead of another Table view.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.