【问题标题】:Drag and Drop in dynamically created GridViews在动态创建的 GridView 中拖放
【发布时间】:2014-01-06 16:51:02
【问题描述】:

我已经动态创建了选项卡,然后我以编程方式在其中添加了一个带有 dragndrop 控制器的 GridView。如果它只有一个选项卡,这一切都有效,但是如果您滚动到第二个选项卡,重新排列项目然后返回,它就会崩溃。我相信这是因为两个选项卡都使用相同的 mDragController。它应该很容易修复,任何想法如何让它们使用单​​独的控制器?

private DragController mDragController;  
private boolean mLongClickStartsDrag = true;   // If true, it takes a long click 

protected void onCreate(Bundle savedInstanceState) {
...

    final TabHost Tabs = (TabHost) findViewById(android.R.id.tabhost);
    Tabs.setup();
    int count;
        for (count =0;count < 2;count++){

            ...

            final int passedTabId = count; 
            NewTab.setContent(new TabHost.TabContentFactory()
            {
                public View createTabContent(String tag)
                {

                   ...

                    GridView dynGrid = new GridView(ManageRooms.this);
                    ...
                    mDragController = new DragController (ManageRooms.this);
                    dynGrid.setAdapter (new ImageCellAdapter (ManageRooms.this, mDragController));
                    layout.addView(dynGrid);


                   return layout;
                }

            });

            Tabs.addTab(NewTab);
        }
}

public boolean startDrag (View v) {
    v.setOnDragListener (mDragController);
    mDragController.startDrag (v);
    return true;
}
} 

【问题讨论】:

    标签: android gridview dynamic android-tabhost


    【解决方案1】:

    解决方案:制作一个 mDragControllers 数组;

    private DragController[] mDragController = new DragController[3];
    

    然后根据当前Tab的id访问每一个。

    【讨论】:

    • 先生,请回答这个问题link
    猜你喜欢
    • 2019-04-13
    • 1970-01-01
    • 1970-01-01
    • 2010-12-28
    • 1970-01-01
    • 2015-09-10
    • 1970-01-01
    • 2012-07-10
    • 1970-01-01
    相关资源
    最近更新 更多