Source:
private void addChildLayer(Layer childLayer) { View view; if (mChildLayout.findViewWithTag(childLayer) == null) { view = LayoutInflater.from(itemView.getContext()) .inflate(R.layout.adapter_item_group_layer, mChildLayout, false); view.setTag(childLayer); } else { view = mChildLayout.findViewWithTag(childLayer); } ((LinearLayout.LayoutParams) view.getLayoutParams()).setMarginStart( itemView.getResources().getDimensionPixelSize(R.dimen.adapter_item_child_margin_start)); if (mRadioGroup != null) { CheckBox checkBox = view.findViewById(R.id.layerCheckbox); checkBox.setVisibility(View.GONE); RadioButton radioButton = view.findViewWithTag("radioButton"); if (radioButton == null) { radioButton = new RadioButton(itemView.getContext()); radioButton.setTag("radioButton"); ((ViewGroup) view).addView(radioButton, 0); } radioButton.setOnCheckedChangeListener(null); radioButton.setChecked(childLayer.isVisible()); radioButton.setOnCheckedChangeListener( ((buttonView, isChecked) -> mOnLayerCheckedChangedListener.layerCheckedChanged(childLayer, isChecked))); ((TextView) view.findViewById(R.id.layerNameTextView)).setText(childLayer.getName()); if (mRadioGroup.findViewWithTag(childLayer) == null) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) parent.removeView(view); mRadioGroup.addView(view); } } else { ((CheckBox) view.findViewById(R.id.layerCheckbox)).setOnCheckedChangeListener(null); ((CheckBox) view.findViewById(R.id.layerCheckbox)).setChecked(childLayer.isVisible()); ((CheckBox) view.findViewById(R.id.layerCheckbox)).setOnCheckedChangeListener( (buttonView, isChecked) -> mOnLayerCheckedChangedListener.layerCheckedChanged(childLayer, isChecked)); ((TextView) view.findViewById(R.id.layerNameTextView)).setText(childLayer.getName()); if (mChildLayout.findViewWithTag(childLayer) == null) { mChildLayout.addView(view); } } }

Target:
private void addChildLayer(Layer childLayer) { View view; if (mChildLayout.findViewWithTag(childLayer) == null) { view = LayoutInflater.from(itemView.getContext()) .inflate(R.layout.adapter_item_group_layer, mChildLayout, false); view.setTag(childLayer); } else { view = mChildLayout.findViewWithTag(childLayer); } ((LinearLayout.LayoutParams) view.getLayoutParams()).setMarginStart( itemView.getResources().getDimensionPixelSize(R.dimen.adapter_item_child_margin_start)); CheckBox checkBox = view.findViewById(R.id.layerCheckbox); if (mRadioGroup != null) { checkBox.setVisibility(View.GONE); RadioButton radioButton = view.findViewWithTag("radioButton"); if (radioButton == null) { radioButton = new RadioButton(itemView.getContext()); radioButton.setTag("radioButton"); ((ViewGroup) view).addView(radioButton, 0); } radioButton.setOnCheckedChangeListener(null); radioButton.setChecked(childLayer.isVisible()); radioButton.setOnCheckedChangeListener( ((buttonView, isChecked) -> mOnLayerCheckedChangedListener.layerCheckedChanged(childLayer, isChecked))); TextView textView = (TextView) view.findViewById(R.id.layerNameTextView); textView.setText(childLayer.getName()); if (mRadioGroup.findViewWithTag(childLayer) == null) { ViewGroup parent = (ViewGroup) view.getParent(); if (parent != null) { parent.removeView(view); } mRadioGroup.addView(view); } } else { checkBox.setOnCheckedChangeListener(null); checkBox.setChecked(childLayer.isVisible()); checkBox.setOnCheckedChangeListener( (buttonView, isChecked) -> mOnLayerCheckedChangedListener.layerCheckedChanged(childLayer, isChecked)); TextView textView = (TextView) view.findViewById(R.id.layerNameTextView); textView.setText(childLayer.getName()); if (mChildLayout.findViewWithTag(childLayer) == null) { mChildLayout.addView(view); } } }