Settext on RadioButton in custom RadioGroup

plaufable

New Member
I am trying to create a custom RadioGroup widget with default RadioButtons that don't have to be specified in xml.Class Definition:\[code\]package com.while1.tasks.widget;import android.content.Context;import android.util.AttributeSet;import android.widget.RadioButton;import android.widget.RadioGroup;public class TaskSortRadioGroup extends RadioGroup { public TaskSortRadioGroup(Context context) { super(context); setupOptions(); } public TaskSortRadioGroup(Context context, AttributeSet attrs) { super(context, attrs); setupOptions(); } private void setupOptions() { RadioButton rb = new RadioButton(getContext()); rb.setWidth(LayoutParams.WRAP_CONTENT); rb.setHeight(LayoutParams.WRAP_CONTENT); rb.setText("Option 1"); addView(rb); }}\[/code\]Usage in xml:\[code\]<!-- Custom RadioGroup --><com.while1.tasks.widget.TaskSortRadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" /><!-- Normal RadioGroup for comparison --><RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This Works" /></RadioGroup>\[/code\]The RadioButton gets created but "Option 1" never displays, and if I try to change the background color, the RadioButton disappears completely. The normal RadioGroup I put below it correctly displays the RadioButton with "This Works" as its text. What am I doing wrong?
 
Back
Top