{"record":{"id":"d3eed8be47626e83","repo":"daimajia/AndroidSwipeLayout","slug":"child-does-not-belong-to-swipelistener","errorCode":null,"errorMessage":"Child does not belong to SwipeListener.","messagePattern":"Child does not belong to SwipeListener\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"library/src/main/java/com/daimajia/swipe/SwipeLayout.java","lineNumber":179,"sourceCode":"        mSwipeDeniers.clear();\n    }\n\n    public interface OnRevealListener {\n        void onReveal(View child, DragEdge edge, float fraction, int distance);\n    }\n\n    /**\n     * bind a view with a specific\n     * {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}\n     *\n     * @param childId the view id.\n     * @param l       the target\n     *                {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}\n     */\n    public void addRevealListener(int childId, OnRevealListener l) {\n        View child = findViewById(childId);\n        if (child == null) {\n            throw new IllegalArgumentException(\"Child does not belong to SwipeListener.\");\n        }\n\n        if (!mShowEntirely.containsKey(child)) {\n            mShowEntirely.put(child, false);\n        }\n        if (mRevealListeners.get(child) == null)\n            mRevealListeners.put(child, new ArrayList<OnRevealListener>());\n\n        mRevealListeners.get(child).add(l);\n    }\n\n    /**\n     * bind multiple views with an\n     * {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}.\n     *\n     * @param childIds the view id.\n     * @param l        the {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}\n     */","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/daimajia/AndroidSwipeLayout/blob/5f8678b04751fb8510a88586b22e07ccf64bca99/library/src/main/java/com/daimajia/swipe/SwipeLayout.java#L161-L197","documentation":"SwipeLayout.addRevealListener(childId, l) resolves the child view with findViewById(childId) inside the SwipeLayout's own hierarchy. If no view with that id exists as a descendant of the SwipeLayout, the library throws IllegalArgumentException. It signals that the reveal-listener target id does not belong to this layout.","triggerScenarios":"Calling addRevealListener(int childId, OnRevealListener l) with an id that is not defined in the SwipeLayout's XML children, a wrong id from another layout file, or calling it before the layout/ids exist.","commonSituations":"Developer passes an id from the item layout root or a different item layout; ids renamed in XML refactor; addRevealListener invoked in code targeting a view inside a different SwipeLayout instance.","solutions":["Use the id of a direct child of the SwipeLayout as declared in its layout XML","Verify the id exists in the exact item layout inflated for this SwipeLayout ( findViewById is called on the SwipeLayout itself)","Check that addRevealListener is called after the view hierarchy is inflated (e.g. after setContentView/adapter bind)","Re-check imports: ensure the int id comes from R.id of this project, not a stale or wrong R class"],"exampleFix":"// before\nswipeLayout.addRevealListener(R.id.bottom_wrapper_item_2, new SwipeLayout.OnRevealListener() { ... }); // id not inside this SwipeLayout\n// after\nswipeLayout.addRevealListener(R.id.trash, new SwipeLayout.OnRevealListener() { ... }); // trash is a child view in the SwipeLayout's XML","handlingStrategy":"validation","validationCode":"View child = swipeLayout.findViewById(childId);\nif (child == null) {\n    throw new IllegalStateException(\"id \" + childId + \" is not a child of this SwipeLayout\");\n}\nswipeLayout.addRevealListener(childId, listener);","typeGuard":"boolean isChildOfSwipeLayout(SwipeLayout layout, int childId) {\n    return layout.findViewById(childId) != null;\n}","tryCatchPattern":"try {\n    swipeLayout.addRevealListener(childId, listener);\n} catch (IllegalArgumentException e) {\n    Log.e(TAG, \"reveal listener target id not in SwipeLayout: \" + childId, e);\n}","preventionTips":["Keep reveal listener target ids declared inside the SwipeLayout's own XML subtree","Call addRevealListener only after inflation is complete","Grep the item layout XML to confirm the id exists before referencing it in code"],"tags":["android","android-view","illegal-argument","view-hierarchy"],"backgroundTag":"resource-not-found","analyzedSha":"5f8678b04751fb8510a88586b22e07ccf64bca99","analyzedAt":"2026-09-08T03:35:37.231Z","contentChangedAt":"2026-09-08T03:35:37.231Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}