{"record":{"id":"e1d8863183e6e468","repo":"material-components/material-components-android","slug":"only-one-revealablelistitem-with-start-gravity-is","errorCode":null,"errorMessage":"Only one RevealableListItem with start gravity is supported.","messagePattern":"Only one RevealableListItem with start gravity is supported\\.","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"lib/java/com/google/android/material/listitem/ListItemLayout.java","lineNumber":250,"sourceCode":"        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) {\n      contentView = child;\n    }\n  }\n\n  @Override\n  public void onViewRemoved(View child) {","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/material-components/material-components-android/blob/ac7e18efeefb331850c561faf9ab8bf81d27ba68/lib/java/com/google/android/material/listitem/ListItemLayout.java#L232-L268","documentation":"ListItemLayout supports at most one RevealableListItem child aligned to the start (left gravity in LTR). addView stores it in swipeToRevealLayoutLeft; a second start-aligned RevealableListItem makes the two candidates ambiguous and the layout throws UnsupportedOperationException.","triggerScenarios":"Adding two RevealableListItem children both with start/left gravity to one ListItemLayout, via XML or addView; swapping a reveal view at runtime without removing the old one.","commonSituations":"A/B testing two reveal designs where the old view is not removed; refactoring layouts and leaving a stray reveal container with layout_gravity=\"start\".","solutions":["Have exactly one start-gravity RevealableListItem; embed multiple start actions within it.","Dynamically replacing: remove the previous start reveal view before adding a new one.","Run a layout lint/inspection for duplicate RevealableListItem siblings with identical gravity."],"exampleFix":"// before (dynamic)\nlistItemLayout.addView(newStartReveal); // old start reveal still attached -> throws\n\n// after\nif (listItemLayout.findViewById(R.id.start_reveal) != null) {\n  listItemLayout.removeView(listItemLayout.findViewById(R.id.start_reveal));\n}\nlistItemLayout.addView(newStartReveal);","handlingStrategy":"validation","validationCode":"View existing = listItemLayout.findViewById(R.id.start_reveal);\nif (existing != null) listItemLayout.removeView(existing);\nlistItemLayout.addView(newStartRevealView);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Exactly one start-gravity RevealableListItem per layout.","Give reveal children stable ids so duplicates are detectable before addView.","Lint custom XML for repeated reveal children with identical gravity."],"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"}