{"record":{"id":"13c4c5b76da0a2aa","repo":"material-components/material-components-android","slug":"only-one-swipeablelistitem-view-is-allowed-in-a-li","errorCode":null,"errorMessage":"Only one SwipeableListItem view is allowed in a ListItemLayout.","messagePattern":"Only one SwipeableListItem view is allowed in a ListItemLayout\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/listitem/ListItemLayout.java","lineNumber":260,"sourceCode":"      if (isRightAligned(child)) {\n        if (swipeToRevealLayoutRight != null) {\n          throw new UnsupportedOperationException(\n              \"Only one RevealableListItem with end gravity is supported.\");\n        }\n        swipeToRevealLayoutRight = child;\n      } else {\n        if (swipeToRevealLayoutLeft != null) {\n          throw new UnsupportedOperationException(\n              \"Only one RevealableListItem with start gravity is supported.\");\n        }\n        swipeToRevealLayoutLeft = child;\n      }\n      // Start the reveal view at a desired width of 0\n      ((RevealableListItem) child).setRevealedWidth(0);\n      // Make sure reveal view has lower elevation\n      child.setElevation(getElevation() - 1);\n    } else if (contentView != null && child instanceof SwipeableListItem) {\n      throw new UnsupportedOperationException(\n          \"Only one SwipeableListItem view is allowed in a ListItemLayout.\");\n    } else if (child instanceof SwipeableListItem) {\n      contentView = child;\n    }\n  }\n\n  @Override\n  public void onViewRemoved(View child) {\n    super.onViewRemoved(child);\n    if (child == swipeToRevealLayoutLeft) {\n      swipeToRevealLayoutLeft = null;\n    } else if (child == swipeToRevealLayoutRight) {\n      swipeToRevealLayoutRight = null;\n    } else if (contentView == child) {\n      contentView = null;\n    }\n\n    if (!swipeToRevealLayoutExists() || contentView == null) {","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/listitem/ListItemLayout.java#L242-L278","documentation":"ListItemLayout designates the first SwipeableListItem child as its swipeable content view (contentView). If another SwipeableListItem is added while contentView is already set, the layout cannot know which view to translate during swipes, so addView throws UnsupportedOperationException.","triggerScenarios":"Two views implementing SwipeableListItem in the same ListItemLayout (e.g. a custom content view plus a nested swipeable container); adding a second content view dynamically after the first bound one.","commonSituations":"Wrapping content in an extra swipeable container 'to be safe'; refactoring that nests SwipeableListItem implementations; third-party custom views implementing the interface unintentionally.","solutions":["Keep exactly one SwipeableListItem per ListItemLayout — it should be the main content view.","Ensure custom content views implement SwipeableListItem only once at the top level; nested helpers should not implement the interface.","When swapping content dynamically, remove the old content view before adding the new one."],"exampleFix":"<!-- before -->\n<ListItemLayout>\n  <SwipeableContentA .../>\n  <SwipeableContentB .../> <!-- throws: second SwipeableListItem -->\n</ListItemLayout>\n\n<!-- after: one swipeable content; second area is a plain view inside it -->\n<ListItemLayout>\n  <SwipeableContent>\n    <PlainHeaderView .../><PlainBodyView .../>\n  </SwipeableContent>\n  <RevealItem layout_gravity=\"end\" .../>\n</ListItemLayout>","handlingStrategy":"validation","validationCode":"View oldContent = listItemLayout.findViewById(R.id.swipeable_content);\nif (oldContent != null) listItemLayout.removeView(oldContent);\nlistItemLayout.addView(newSwipeableContent);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Design item layouts with exactly one SwipeableListItem as the content root.","Make helper/inner views NOT implement SwipeableListItem.","Review third-party custom views for unintended interface implementations."],"tags":["material-components","listitem","swipe","layout-structure"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}