【发布时间】: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