当我致电BottomSheetDialog
时,我一直面临着崩溃。这个崩溃突然发生在一个工作正常的代码上,我确信我没有更新任何支持库或设计库。
似乎BottomSheetDialog
的夸大布局与之前的布局有所不同。顶级视图已从FrameLayout
更改为CoordinatorLayout
。
最奇怪的是,在另一个项目中使用了相同的库版本,它工作正常。 还有其他人遇到过这个问题吗?
Caused by: java.lang.ClassCastException: android.support.design.widget.CoordinatorLayout cannot be cast to android.widget.FrameLayout
at com.doctor247.patient.app.view.helper.ui.CustomBottomSheetDialog.wrapInBottomSheet(CustomBottomSheetDialog.java:97)
at com.doctor247.patient.app.view.helper.ui.CustomBottomSheetDialog.setContentView(CustomBottomSheetDialog.java:67)
at android.support.v4.app.DialogFragment.onActivityCreated(DialogFragment.java:411)
...
UploadDocumentsFragment.java
public class UploadShareDocumentsFragment extends AppCompatDialogFragment implements View.OnClickListener {
LinearLayout cameraContainer, galleryContainer, documentsContainer, uploadsContainer;
TextView close;
ArrayList<Document> sharedUserDocuments;
ArrayList<Document> patientDocuments;
IUploadChooserListener uploadChooserListener;
public UploadShareDocumentsFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (getActivity() instanceof HomeActivity) {
// then inflate without document sharing
} else {
}
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_upload_documents, container, false);
sharedUserDocuments = getArguments().getParcelableArrayList(Constant.SHARED_DOCUMENTS);
patientDocuments = getArguments().getParcelableArrayList(Constant.PATIENT_DOCUMENTS);
cameraContainer = (LinearLayout) v.findViewById(R.id.cameraContainer);
galleryContainer = (LinearLayout) v.findViewById(R.id.galleryContainer);
documentsContainer = (LinearLayout) v.findViewById(R.id.documentsContainer);
uploadsContainer = (LinearLayout) v.findViewById(R.id.uploadsContainer);
if (getActivity() instanceof HomeActivity)
uploadsContainer.setVisibility(View.GONE);
close = (TextView) v.findViewById(R.id.close);
close.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UploadShareDocumentsFragment.this.dismiss();
}
});
cameraContainer.setOnClickListener(this);
galleryContainer.setOnClickListener(this);
documentsContainer.setOnClickListener(this);
uploadsContainer.setOnClickListener(this);
return v;
}
public void setUploadChooserListener(IUploadChooserListener uploadChooserListener) {
this.uploadChooserListener = uploadChooserListener;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new UploadDocumentFragment.BottomSheetDialog(getActivity(), getTheme());
}
@Override
public void onClick(View v) {
if (v.getId() == R.id.cameraContainer) {
uploadChooserListener.onCameraClicked();
} else if (v.getId() == R.id.galleryContainer) {
uploadChooserListener.onGalleryClicked();
} else if (v.getId() == R.id.documentsContainer) {
uploadChooserListener.onDocumentClicked();
} else if (v.getId() == R.id.uploadsContainer) {
// start activity for result to uploaded Documents activity and get the selected document
Intent intent = new Intent(getActivity(), UploadedDocumentsListActivity.class);
intent.putExtra(PATIENT, ((DoctorDetailsActivity) getActivity()).patient);
intent.putExtra(DOCTOR, ((DoctorDetailsActivity) getActivity()).doctor);
intent.putParcelableArrayListExtra(Constant.SHARED_DOCUMENTS, sharedUserDocuments);
intent.putParcelableArrayListExtra(Constant.PATIENT_DOCUMENTS, patientDocuments);
//intent.putParcelableArrayListExtra(DOCUMENTS, ((DoctorDetailsActivity)getActivity()).getDocuments());
getActivity().startActivityForResult(intent, SHARE_FILE);
// intent.putExtra(Constant.)
}
this.dismiss();
}
static class BottomSheetDialog extends android.support.design.widget.BottomSheetDialog {
public BottomSheetDialog(@NonNull Context context, @StyleRes int theme) {
super(context, theme);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
int width = getContext().getResources().getDimensionPixelSize(R.dimen.bottom_sheet_width);
//noinspection ConstantConditions
getWindow().setLayout(
width > 0 ? width : ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
}
}
}
fragment_upload_documents.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="@dimen/activity_vertical_margin"
tools:context="com.doctor247.patient.app.view.fragment.dialog.UploadShareDocumentsFragment">
<com.doctor247.patient.app.view.helper.CustomFontTextView
style="@style/TextAppearance.Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="@string/upload_document"
app:fontName="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/cameraContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/camera" />
<com.doctor247.patient.app.view.helper.CustomFontTextView
style="@style/TextAppearance.Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/camera"
app:fontName="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/galleryContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/gallery" />
<com.doctor247.patient.app.view.helper.CustomFontTextView
style="@style/TextAppearance.Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/gallery"
app:fontName="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_horizontal_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/documentsContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_pdf" />
<com.doctor247.patient.app.view.helper.CustomFontTextView
style="@style/TextAppearance.Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pdf"
app:fontName="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/uploadsContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/document" />
<com.doctor247.patient.app.view.helper.CustomFontTextView
style="@style/TextAppearance.Info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/uploads"
app:fontName="bold" />
</LinearLayout>
</LinearLayout>
<com.doctor247.patient.app.view.helper.CustomFontTextView
android:id="@+id/close"
style="@style/TextAppearance.Prefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:text="@string/close"
app:fontName="bold" />
</LinearLayout>