RadioRealButton icon indicating copy to clipboard operation
RadioRealButton copied to clipboard

How can I add radioButton programmatically

Open potatoker opened this issue 6 years ago • 2 comments

I want to add more radioButton when the app is running. Can I add radioButton programmatically?

potatoker avatar Jan 11 '18 03:01 potatoker

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.

jonandersen avatar Jun 11 '18 21:06 jonandersen

// 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.

odyodyodys avatar Sep 28 '18 08:09 odyodyodys