{"record":{"id":"767c17a9237fed22","repo":"material-components/material-components-android","slug":"only-one-revealablelistitem-with-end-gravity-is-su","errorCode":null,"errorMessage":"Only one RevealableListItem with end gravity is supported.","messagePattern":"Only one RevealableListItem with end gravity is supported\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/listitem/ListItemLayout.java","lineNumber":244,"sourceCode":"        positionState = FIRST_STATE_SET;\n        break;\n      case POSITION_LAST:\n        positionState = LAST_STATE_SET;\n        break;\n      case POSITION_MIDDLE:\n        positionState = MIDDLE_STATE_SET;\n        break;\n    }\n    refreshDrawableState();\n  }\n\n  @Override\n  public void addView(View child, int index, ViewGroup.LayoutParams params) {\n    super.addView(child, index, params);\n    if (child instanceof RevealableListItem) {\n      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) {","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/listitem/ListItemLayout.java#L226-L262","documentation":"ListItemLayout (swipe-to-reveal list item container) supports at most one RevealableListItem child aligned to the end (right gravity in LTR). addView tracks that child in swipeToRevealLayoutRight; when a second end-aligned RevealableListItem is added, the layout cannot disambiguate which view to reveal, so it throws UnsupportedOperationException.","triggerScenarios":"Inflating or programmatically adding two views implementing RevealableListItem both with end/right gravity into one ListItemLayout; XML layouts with two reveal containers using layout_gravity=\"end\".","commonSituations":"Design iterating toward two actions on one side; merging layouts by copy-paste leaving a duplicate reveal container; conditional UI code adding a reveal view without removing the previous one.","solutions":["Keep exactly one end-gravity RevealableListItem per ListItemLayout; place multiple end actions inside that single reveal container (it can itself hold several buttons).","If two reveal areas are truly needed, use start gravity for one and end gravity for the other.","When adding reveal views dynamically, remove the existing one first: removeView(swipeToRevealLayoutRight) before addView."],"exampleFix":"<!-- before: two end-gravity reveal children -->\n<com.google.android.material.listitem.ListItemLayout ...>\n  <RevealLayoutEnd1 layout_gravity=\"end\" .../>\n  <RevealLayoutEnd2 layout_gravity=\"end\" .../> <!-- throws -->\n</...>\n\n<!-- after: single end reveal container holding both actions -->\n<com.google.android.material.listitem.ListItemLayout ...>\n  <RevealContainer layout_gravity=\"end\">\n    <Button .../><Button .../>\n  </RevealContainer>\n</...>","handlingStrategy":"validation","validationCode":"int endReveals = 0;\nfor (int i = 0; i < listItemLayout.getChildCount(); i++) {\n  View c = listItemLayout.getChildAt(i);\n  if (c instanceof RevealableListItem && ViewCompat.getLayoutDirection(c) == LTR\n      && isRightGravity(c)) endReveals++;\n}\nif (endReveals > 1) throw new IllegalStateException(\"Duplicate end reveal children in XML\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Template rule: at most one start reveal + one end reveal per ListItemLayout.","Put multiple same-side actions inside a single reveal container.","Remove old reveal views before dynamically adding replacements."],"tags":["material-components","listitem","swipe","layout-structure"],"backgroundTag":null,"analyzedSha":"ac7e18efeefb331850c561faf9ab8bf81d27ba68","analyzedAt":"2026-08-14T15:35:35.735Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}