daimajia/AndroidSwipeLayout · error · IllegalArgumentException
Child does not belong to SwipeListener.
Error message
Child does not belong to SwipeListener.
What it means
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.
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
Example fix
// before
swipeLayout.addRevealListener(R.id.bottom_wrapper_item_2, new SwipeLayout.OnRevealListener() { ... }); // id not inside this SwipeLayout
// after
swipeLayout.addRevealListener(R.id.trash, new SwipeLayout.OnRevealListener() { ... }); // trash is a child view in the SwipeLayout's XML Defensive patterns
Strategy: validation
Validate before calling
View child = swipeLayout.findViewById(childId);
if (child == null) {
throw new IllegalStateException("id " + childId + " is not a child of this SwipeLayout");
}
swipeLayout.addRevealListener(childId, listener); Type guard
boolean isChildOfSwipeLayout(SwipeLayout layout, int childId) {
return layout.findViewById(childId) != null;
} Try / catch
try {
swipeLayout.addRevealListener(childId, listener);
} catch (IllegalArgumentException e) {
Log.e(TAG, "reveal listener target id not in SwipeLayout: " + childId, e);
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
AI-assisted analysis of daimajia/AndroidSwipeLayout@5f8678b047 (2026-09-08).
Data as JSON: /api/errors/d3eed8be47626e83.
Report an issue: GitHub.
Appendix: source
Thrown at library/src/main/java/com/daimajia/swipe/SwipeLayout.java:179
mSwipeDeniers.clear();
}
public interface OnRevealListener {
void onReveal(View child, DragEdge edge, float fraction, int distance);
}
/**
* bind a view with a specific
* {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}
*
* @param childId the view id.
* @param l the target
* {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}
*/
public void addRevealListener(int childId, OnRevealListener l) {
View child = findViewById(childId);
if (child == null) {
throw new IllegalArgumentException("Child does not belong to SwipeListener.");
}
if (!mShowEntirely.containsKey(child)) {
mShowEntirely.put(child, false);
}
if (mRevealListeners.get(child) == null)
mRevealListeners.put(child, new ArrayList<OnRevealListener>());
mRevealListeners.get(child).add(l);
}
/**
* bind multiple views with an
* {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}.
*
* @param childIds the view id.
* @param l the {@link com.daimajia.swipe.SwipeLayout.OnRevealListener}
*/View on GitHub (pinned to 5f8678b047)