MultipleChoiceOptionItem extends OptionItem implements CompoundButton.OnCheckedChangeListener { public MultipleChoiceOptionItem setLabels(final List<String> labels) { if (labels == null) { throw new IllegalArgumentException(getContext().getString(R.string.msdkui_exception_labels_null)); } for (final String label : labels) { final View view = View.inflate(getContext(), R.layout.multiple_option_item, null); final TextView labelView = (TextView) view.findViewById(R.id.multiple_item_label); labelView.setText(label); final CheckBox selectionView = (CheckBox) view.findViewById(R.id.multiple_item_value); selectionView.setOnCheckedChangeListener(this); mItemList.add(getRow(labelView, selectionView)); addView(view); } return this; } MultipleChoiceOptionItem(final Context context);  MultipleChoiceOptionItem(final Context context, final AttributeSet attrs);  MultipleChoiceOptionItem(final Context context, final AttributeSet attrs, final int defStyleAttr); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)  MultipleChoiceOptionItem(final Context context, final AttributeSet attrs, final int defStyleAttr, final int defStyleRes); List<String> getLabels(); MultipleChoiceOptionItem setLabels(final List<String> labels); void selectLabels(final List<String> labels); List<String> getSelectedLabels(); boolean isItemSelected(final String id); @Override void onCheckedChanged(final CompoundButton buttonView, final boolean isChecked);  }
@Test public void testCallback() { mMultipleChoiceOptionItem.setListener(new OptionItem.OnChangedListener() { @Override public void onChanged(OptionItem item) { mCallbackCalled = true; } }); final List<String> ids = Collections.singletonList(getString(R.string.msdkui_fastest)); mMultipleChoiceOptionItem.setLabels(ids); assertThat(mMultipleChoiceOptionItem.getChildCount(), equalTo(1)); final View view = mMultipleChoiceOptionItem.getChildAt(0); final TextView labelView = (TextView) view.findViewById(R.id.multiple_item_label); final CheckBox selectionView = (CheckBox) view.findViewById(R.id.multiple_item_value); assertNotNull(labelView); assertNotNull(selectionView); selectionView.setChecked(true); assertThat(mCallbackCalled, is(true)); }