Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android通过拖拽传递数据_Android_Listview_Android Viewholder - Fatal编程技术网

Android通过拖拽传递数据

Android通过拖拽传递数据,android,listview,android-viewholder,Android,Listview,Android Viewholder,通过拖放传递数据的完整证明方式是什么 在我的情况下,我有两个列表,可以将元素从一个列表拖到另一个列表。 所以我们拖动的列表已经有了相关的数据。 从我搜索的内容来看,通常的方法是通过视图setTag()和getTag()方法存储数据。这也是我要做的,但由于两个列表都使用视图持有者模式,实际数据将存储在持有者中。然后将保持架设置为视图标记。 然而,我也听说您不应该在视图或holder中存储数据(我在列表适配器中使用视图holder模式) 那么,将数据从一个列表传递到另一个列表的最佳方式是什么呢?尝试

通过拖放传递数据的完整证明方式是什么

在我的情况下,我有两个列表,可以将元素从一个列表拖到另一个列表。 所以我们拖动的列表已经有了相关的数据。 从我搜索的内容来看,通常的方法是通过视图setTag()和getTag()方法存储数据。这也是我要做的,但由于两个列表都使用视图持有者模式,实际数据将存储在持有者中。然后将保持架设置为视图标记。 然而,我也听说您不应该在视图或holder中存储数据(我在列表适配器中使用视图holder模式)


那么,将数据从一个列表传递到另一个列表的最佳方式是什么呢?

尝试将数据存储在根活动或片段中:

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;
            }
        }
    }
也许,这会有帮助