Skip to content
This repository has been archived by the owner on Mar 27, 2022. It is now read-only.

How can I add radioButton programmatically #35

Open
potatoker opened this issue Jan 11, 2018 · 2 comments
Open

How can I add radioButton programmatically #35

potatoker opened this issue Jan 11, 2018 · 2 comments

Comments

@potatoker
Copy link

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

@jonandersen
Copy link

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.

@odyodyodys
Copy link

odyodyodys commented Sep 28, 2018

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants