{"record":{"id":"e3e9b3d4f174a872","repo":"Tencent/QMUI_Android","slug":"target-already-exists-other-parent-view","errorCode":null,"errorMessage":"Target already exists other parent view.","messagePattern":"Target already exists other parent view\\.","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"qmui/src/main/java/com/qmuiteam/qmui/widget/pullLayout/QMUIPullLayout.java","lineNumber":206,"sourceCode":"            }else{\n                setHorOffsetToTargetOffsetHelper(mScroller.getCurrX());\n                setVerOffsetToTargetOffsetHelper(mScroller.getCurrY());\n                postInvalidateOnAnimation();\n            }\n        }\n    }\n\n    public void setStopTargetViewFlingImpl(@NonNull StopTargetViewFlingImpl stopTargetViewFlingImpl) {\n        mStopTargetViewFlingImpl = stopTargetViewFlingImpl;\n    }\n\n    public void setMinScrollDuration(int minScrollDuration) {\n        mMinScrollDuration = minScrollDuration;\n    }\n\n    public void setTargetView(@NonNull View view) {\n        if (view.getParent() != this) {\n            throw new RuntimeException(\"Target already exists other parent view.\");\n        }\n        if (view.getParent() == null) {\n            LayoutParams lp = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);\n            addView(view, lp);\n        }\n        innerSetTargetView(view);\n    }\n\n    private void innerSetTargetView(@NonNull View view) {\n        mTargetView = view;\n        mTargetOffsetHelper = new QMUIViewOffsetHelper(view);\n    }\n\n    public void setActionView(View view, LayoutParams lp) {\n        PullActionBuilder builder = new PullActionBuilder(view, lp.edge)\n                .canOverPull(lp.canOverPull)\n                .pullRate(lp.pullRate)\n                .needReceiveFlingFromTargetView(lp.needReceiveFlingFromTarget)","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/Tencent/QMUI_Android/blob/026e7d486677d6593a96689cd590ec3561176717/qmui/src/main/java/com/qmuiteam/qmui/widget/pullLayout/QMUIPullLayout.java#L188-L224","documentation":"QMUIPullLayout.setTargetView(view) throws when the given view's parent is neither null nor this QMUIPullLayout, meaning the view is already attached to another parent. The layout refuses to adopt a view that belongs elsewhere.","triggerScenarios":"Programmatically calling pullLayout.setTargetView(someView) where someView is currently attached to a different ViewGroup (e.g. still in another layout or another container).","commonSituations":"Reusing a view across two pull layouts; forgetting to call parentView.removeView(view) (or removeAllViews) before assigning it; moving a target view between pull layouts at runtime.","solutions":["Call view's current parent's removeView(view) before setTargetView(view).","Inflate a fresh view instance for this pull layout instead of reusing an attached one.","Only pass views that are direct XML children of this QMUIPullLayout or detached views."],"exampleFix":"// before\npullLayout.setTargetView(recyclerView); // recyclerView still attached elsewhere\n// after\nif (recyclerView.getParent() instanceof ViewGroup) {\n    ((ViewGroup) recyclerView.getParent()).removeView(recyclerView);\n}\npullLayout.setTargetView(recyclerView);","handlingStrategy":"type-guard","validationCode":"Object parent = view.getParent();\nif (parent == null || parent == pullLayout) {\n    pullLayout.setTargetView(view);\n}","typeGuard":"private static boolean canSetTarget(QMUIPullLayout layout, View v) {\n    return v.getParent() == null || v.getParent() == layout;\n}","tryCatchPattern":"try {\n    pullLayout.setTargetView(view);\n} catch (RuntimeException e) {\n    ViewGroup old = (ViewGroup) view.getParent();\n    if (old != null) old.removeView(view);\n    pullLayout.setTargetView(view);\n}","preventionTips":["Detach a view from its previous parent before assigning it as target.","Inflate fresh view instances per pull layout instead of sharing.","Only reuse views that are direct XML children of this pull layout."],"tags":["android","qmui","view-parent","illegal-state"],"backgroundTag":"invalid-state-transition","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"}