RadioRealButton
RadioRealButton copied to clipboard
How can I add radioButton programmatically
I want to add more radioButton when the app is running. Can I add radioButton programmatically?
Was trying to find a solution for this as well. There seems to be some apis, but if we can get an example for this it would be much easier to get it working.
// Create the button
RadioRealButton radioButton = new RadioRealButton(context);
radioButton.setId(View.generateViewId());
radioButton.setText("radio");
radioButton.setTextColor(Color.BLACK);
// Add drawable
radioButton.setDrawable(drawable);
radioButton.setDrawableGravity(RadioRealButton.DrawableGravity.TOP);
radioButton.setDrawableSizeByDp(24, 24);
// Add it to the group
radioGroup.addView(radioButton);
Although this seems to work, the added drawable is hidden initially because RadioRealButton.setDrawableAttrs()
hides it, so there's a bug.
To fix this, you need to manually make it visible at the end
radioButton.getImageView().setVisibility(View.VISIBLE);
But there are more bugs, so you cannot easily set gravity to drawable.