0

I have dynamically created tabs, in which I then programatically add a GridView with dragndrop controller. It all works if its only one tab, but if you scroll to the second one, rearrange items and then back, it crashes. I believe its because both tabs are using the same mDragController. It should be fairly easy to fix, any Ideas how to make them use separate controllers?

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;
}
} 
Ravi
  • 34,851
  • 21
  • 122
  • 183

1 Answers1

0

Solution: making an array of mDragControllers;

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

and then accessing each one according to the id of the current Tab.

  • sir Please answer this question [link](http://stackoverflow.com/questions/20988505/open-child-activity-in-tab-host-android) – Bishnu Kumar Jan 08 '14 at 07:17