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

How can I add radioButton programmatically #35

Description

@potatoker

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

Activity

  1. jonandersen commented on Jun 11, 2018

    @jonandersen

    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.

  2. odyodyodys commented on Sep 28, 2018

    @odyodyodys
    // 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 join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions