如何在android studio中链接ListViews的子视图和箭头视图?

时间:2017-04-02 11:42:37

标签: android listview

我有一个ViewGroup,它包含一堆水平排序的listViews。我需要的是当我在ListView ChildView上进行Longclick时,我可以选择另一个另一个ListView的另一个childView,并将两个视图连同一个类似于它在labView框图中工作的方式的箭头(见下图),你可以在其中拖动箭头并将它从一个项目附加到另一个项目......

LabView block diagram

非常感谢任何帮助

//ViewGroup where listViews are added dynamically 
  <CustomViewGroup
            android:id="@+id/list_layout_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            />

            </CustomViewGroup>

// MainActivity代码 - 单击listView中的项目

    @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {


            ListView listFrom = null; 
            ListView listTo = null;
            String nodeToName = null;
            String nodeFromName = null; 


            Log.e("onItemLongClick", "Long CLick");


            NodeItems current = (NodeItems) parent.getAdapter().getItem(position);


       // First childView selected -- i.e. the item first clicked on
            View rowView = parent.getChildAt(position);


            /** Extract position of the first ChildView item **/

            if (rowView != null) {


                listFrom = (ListView) rowView.getParent();


                Log.e("Send Node position", current.getNodeTask().toString());


                int[] locations = new int[2];

                rowView.getLocationOnScreen(locations);//Get location of first View 

                /** Extract position of the nodeTo item **/

                try {


                    // Let user know to select another node
                    Toast.makeText(this, "Please select another Node: ", Toast.LENGTH_SHORT).show();

                    //Elapsed time to get focus on new child
                    Thread.sleep(3000);

                    //Click on the second view that user wants to connect which belongs to another listView and store in a temp view variable
                    View nodeView = getCurrentFocus();

                    int[] map = new int[2];


                    if (nodeView != null && nodeView.getParent() instanceof ListView && nodeView != rowView) {

                        nodeView.getLocationOnScreen(map); //get location of second View


                        listTo = (ListView) nodeView.getParent();


                        for (int i = 0; i < listTo.getChildCount(); i++) {

                            if (listTo.getChildAt(i) == nodeView) {

                                nodeTaskToName = ((Node) listTo.getNodeAdapter().getItem(i)).getTaskName();


                            }


                        }


                    }



                } catch (InterruptedException e) {
                    e.printStackTrace();
                }


                if (nodeFromName != null && nodeToName != null) {
                    connectNodes(listFrom, listTo, nodeFromName,  nodeToName); //Method connects nodes in a HashMap 


                /** Call another method to add arrow between two methods onTouch based on the two locations **/

           //have no idea how to do this 
                } 







        return true;
    }

0 个答案:

没有答案