javiersantos / BottomDialogs

An Android library that shows a customizable Material-based bottom sheet. API 11+ required.
Apache License 2.0
642 stars 119 forks source link

Crash when showing the same builder two times #16

Closed droididan closed 8 years ago

droididan commented 8 years ago

Hello,

I built the Sheet and show it, then I want to update the title so I set the new title and rebuilt but I show for the second time I get crash:

log: "The specified child already has a parent. You must call removeView() on the child's parent first."

private void showNewEventSheet(String address, LatLng latLng) {
        if (mEventDialog == null) {
            mEventDialog = new BottomDialog.Builder(mActivity)
                    .setTitle(address)
                    .setContent(R.string.radius_content_message)
                    .setPositiveText(R.string.save)
                    .setNegativeText("Cancel")
                    .setCustomView(mSheetView)
                    .setCancelable(false)
                    .onPositive(bottomDialog -> {
                        new GeoModel(mRadius, latLng.latitude, latLng.longitude, address).save();
                        enterRadiusAndStayStillFence(latLng, mRadius);
                        getViewState().showFenceIndicate();
                        getViewState().showSettingsFab();
                    })
                    .onNegative(bottomDialog -> cancelEvent())
                    .show();
        } else {
            **mEventDialog.getBuilder().setTitle(address).build();**
            mEventDialog.show();
        }
    }
}