How to Dynamically Add Radio Buttons

by | Mar 27, 2013

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.