medyo/Dynamicbox

Error in fragment

devilmac opened this issue · 2 comments

Hi medyo,

I'm trying to use your library but I get this error on "onCreateView" of fragment:

07-03 00:00:44.777  17034-17034/com.federico.colantoni.projects.my_project E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.federico.colantoni.projects.my_project, PID: 17034
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.federico.colantoni.projects.my_project/com.federico.colantoni.projects.my_project.activity.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

Below the code I use:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.my_layout, container, false);

        if (view != null) {
            box = new DynamicBox(getActivity(), view);
            box.showLoadingLayout();
            ...
       }
...
}

Could you explain me how I can get work this library on fragment?

Thanks.

Kind regards.

Please switch your code from onCreateView to onViewCreated or Set directly the layout id to DynamicBox like :
new DynamicBox(getActivity(), R.layout.my_layout);

Hi,

thanks, tonight I'll try it.

EDIT
Hi medyo, I'm trying to use your suggestion without success: I put the constructor of DynamicBox on the "onViewCreated" callback, and I get that the view is not supported. To be more precise, on "onViewCreated" method the view it seems to be a NoSaveStateFrameLayout view, while before return the inflated view on "onCreateView" callback, it is a RelativeLayout view. How is it possible?

PS: I have modified the code of the copy of your library in DynamicBox.java, adding the type of view "nosavestateframelayout" as supported view, like this:

private final String[] mSupportedViews = new String[]{"linearlayout","relativelayout","nosavestateframelayout","scrollview"};

With this modification, the code works fine.