How to Dynamically Add Radio Buttons

Haven’t seen a tutorial for this that isn’t badly spelled and hard to grok, so I’ll try it.

First, include the radio group widget and and declare one. You’ll also need LayoutParams and RadioButton, so include those as well.

Inside your onCreate method, initialize the radio group.

R.id.radio_selection_group is referring to a radio group that’s declared in your XML file, so make sure you have that as well.

Back in SomeAndroidActivity, create a method to dynamically add buttons to the radio group.

Then call that method in onCreate.

Easy pie.

Published by

Shannon Graham

Shannon has been writing brief essays and occasional how-to articles at Rocketships, Unaffiliated (.ca) whenever inspiration strikes, since 2012. She is interested in your opinion.

3 thoughts on “How to Dynamically Add Radio Buttons”

  1. I see you share interesting things here, you can earn some additional money, your blog
    has huge potential, for the monetizing method, just search in google –
    K2 advices how to monetize a website

Leave a Reply

Your email address will not be published. Required fields are marked *