I had created a dynamic radio group which contain onClickListener for each radio button when click. How can i set the first item in the radio group as default selected INCLUDING the onClick action for the first item.
I had try with the code((RadioButton)radioGroup.getChildAt(0)).setChecked(true);
but it only set the item as checked but did not perform any onClick action.
Below is what i done for my dynamic radio button.
public static void createRoutemapButton(final Activity activity, final List<DORouteMapInfo> list, final FlexRadioGroup flexRadioGroup, final ImageView imageView){
LayoutInflater inflater = LayoutInflater.from(activity);
float margin = DensityUtils.dp2px(activity, 85);
float width = DensityUtils.getWidth(activity);
for (final DORouteMapInfo routeMap : list) {
final RadioButton rb = (RadioButton) inflater.inflate(R.layout.item_radiobutton_label, null);
rb.setText(routeMap.getTitle());
FlexboxLayout.LayoutParams params = new FlexboxLayout.LayoutParams((int) (width - margin) / 2, ViewGroup.LayoutParams.WRAP_CONTENT);
params.setMargins(5,0,5,5);
rb.setLayoutParams(params);
rb.setPadding(0,10,0,10);
flexRadioGroup.addView(rb);
flexRadioGroup.setOnCheckedChangeListener(new FlexRadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(@IdRes int checkedId) {
}
});
rb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Picasso.with(activity)
.load(routeMap.getImageURL())
.fit().centerInside()
.into(imageView);
}
});
}
}