{"record":{"id":"5b1205bbb5f7a99d","repo":"Tencent/QMUI_Android","slug":"use-addcontentview-view-qmuiprioritylinearlayout","errorCode":null,"errorMessage":"Use addContentView(View, QMUIPriorityLinearLayout.LayoutParams) for replacement","messagePattern":"Use addContentView\\(View, QMUIPriorityLinearLayout\\.LayoutParams\\) for replacement","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java","lineNumber":261,"sourceCode":"    public interface OnBottomSheetShowListener {\n        void onShow();\n    }\n\n    @Override\n    public void setContentView(View view) {\n        throw new IllegalStateException(\n                \"Use addContentView(View, ConstraintLayout.LayoutParams) for replacement\");\n    }\n\n    @Override\n    public void setContentView(int layoutResId) {\n        throw new IllegalStateException(\n                \"Use addContentView(int) for replacement\");\n    }\n\n    @Override\n    public void setContentView(View view, ViewGroup.LayoutParams params) {\n        throw new IllegalStateException(\n                \"Use addContentView(View, QMUIPriorityLinearLayout.LayoutParams) for replacement\");\n    }\n\n    @Override\n    public void addContentView(View view, ViewGroup.LayoutParams params) {\n        throw new IllegalStateException(\n                \"Use addContentView(View, QMUIPriorityLinearLayout.LayoutParams) for replacement\");\n    }\n\n    public void addContentView(View view, QMUIPriorityLinearLayout.LayoutParams layoutParams) {\n        mRootView.addView(view, layoutParams);\n    }\n\n    public void addContentView(View view) {\n        QMUIPriorityLinearLayout.LayoutParams lp =  new QMUIPriorityLinearLayout.LayoutParams(\n                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);\n        lp.setPriority(QMUIPriorityLinearLayout.LayoutParams.PRIORITY_DISPOSABLE);\n        mRootView.addView(view, lp);","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/widget/dialog/QMUIBottomSheet.java#L243-L279","documentation":"The three-argument form of content setting is likewise forbidden: QMUIBottomSheet.setContentView(View, ViewGroup.LayoutParams) always throws IllegalStateException and points you to addContentView(View, QMUIPriorityLinearLayout.LayoutParams), matching the internal priority-linear layout used for the sheet's content stack.","triggerScenarios":"Calling bottomSheet.setContentView(view, layoutParams) with any ViewGroup.LayoutParams on a QMUIBottomSheet.","commonSituations":"Generic dialog code that passes custom LayoutParams, or framework-level wrappers invoking Dialog.setContentView(view, params) programmatically.","solutions":["Use addContentView(view, new QMUIPriorityLinearLayout.LayoutParams(width, height)) with QMUIPriorityLinearLayout.LayoutParams instead of generic params.","Prefer the QMUIBottomSheet builder API (addView/addTopView) for composing content.","Route shared dialog helpers around QMUIBottomSheet-specific content methods.","Note the QMUIBottomSheet.addContentView(View, ViewGroup.LayoutParams) is itself unsupported here — use the QMUIPriorityLinearLayout.LayoutParams overload specifically."],"exampleFix":"// before\nbottomSheet.setContentView(view, new ViewGroup.LayoutParams(MATCH_PARENT, WRAP_CONTENT)); // throws\n// after\nbottomSheet.addContentView(view, new QMUIPriorityLinearLayout.LayoutParams(\n        QMUIPriorityLinearLayout.LayoutParams.MATCH_PARENT,\n        QMUIPriorityLinearLayout.LayoutParams.WRAP_CONTENT));","handlingStrategy":"try-catch","validationCode":"if (sheet instanceof QMUIBottomSheet && !(params instanceof QMUIPriorityLinearLayout.LayoutParams)) {\n    params = new QMUIPriorityLinearLayout.LayoutParams(params.width, params.height);\n}","typeGuard":"boolean usesQmuiParams(ViewGroup.LayoutParams p) { return p instanceof QMUIPriorityLinearLayout.LayoutParams; }","tryCatchPattern":"try {\n    sheet.setContentView(view, params);\n} catch (IllegalStateException e) {\n    sheet.addContentView(view, new QMUIPriorityLinearLayout.LayoutParams(params.width, params.height));\n}","preventionTips":["Always construct QMUIPriorityLinearLayout.LayoutParams for QMUIBottomSheet content.","Avoid generic ViewGroup.LayoutParams paths when working with bottom sheets.","Route all sheet content through the builder API to bypass layout-param pitfalls.","Note that even QMUIBottomSheet.addContentView(View, ViewGroup.LayoutParams) is unsupported — only the QMUIPriorityLinearLayout.LayoutParams overload works."],"tags":["android","qmui","dialog","unsupported-operation"],"backgroundTag":"unsupported-operation","analyzedSha":"026e7d486677d6593a96689cd590ec3561176717","analyzedAt":"2026-09-06T13:32:24.816Z","contentChangedAt":"2026-09-06T13:32:24.816Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}