Example usage for android.widget RadioGroup RadioGroup

List of usage examples for android.widget RadioGroup RadioGroup

Introduction

In this page you can find the example usage for android.widget RadioGroup RadioGroup.

Prototype

public RadioGroup(Context context) 

Source Link

Usage

From source file:com.example.karspoolingapp.RouteByHitchhikerCar.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.routebyhitchhiker);

    Intent intent = getIntent();//from  ww  w .  j a  v a2  s. c o m
    Bundle bundle = intent.getExtras();
    new_license_number = bundle.getString("pre_end_point");
    //session_username = session.getUsername();
    System.out.println("nayaaa licnse number" + new_license_number);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

    StrictMode.setThreadPolicy(policy);

    // code for dynamic radio button generation
    final RadioButton[] rb = new RadioButton[100];
    rl = (RelativeLayout) findViewById(R.id.rl);
    rg = new RadioGroup(this);

    // Building Parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("car_number", new_license_number));
    System.out.println(params);
    json = jsonParser.makeHttpRequest(READ_COMMENTS_URL2, "POST", params);
    params.clear();
    System.out.println(json);

    try {
        jsonTripDetails = json.getJSONArray("route");
        System.out.println(jsonTripDetails);
        int k = jsonTripDetails.length();
        if (k > 0) {
            for (int i = 0; i < jsonTripDetails.length(); i++) {
                JSONObject c = jsonTripDetails.getJSONObject(i);

                String parent_username_str = c.getString("username");
                String route = c.getString("route");
                String timing = c.getString("timing");
                String seating = c.getString("seating_capacity");
                rb[i] = new RadioButton(this);
                rg.addView(rb[i]);
                rb[i].setText(parent_username_str + "," + route + "," + timing + "," + seating);
                params.clear();

            }
            rl.addView(rg);
            rl.setPadding(50, 50, 50, 50);
        } else {
            Toast.makeText(RouteByHitchhikerCar.this, "No Trip available on these routes", Toast.LENGTH_LONG)
                    .show();
        }

    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();

    }

    addListenerOnButton();

}

From source file:edu.csh.coursebrowser.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_settings);
    this.setTitle("Settings");
    final SharedPreferences sp = SchoolActivity.sp;
    LinearLayout ll = (LinearLayout) this.findViewById(R.id.settings_layout);
    ll.setGravity(Gravity.CENTER);//from w  w  w. j  a  va2 s. c o m
    final TextView tv = new TextView(this);
    if (!sp.contains("quarter")) {
        SharedPreferences.Editor e = sp.edit();
        e.putString("quarter", "20122");
        e.commit();
    }
    tv.setText("Current Quarter: " + sp.getString("quarter", "20122"));
    Button b = new Button(this);
    b.setText("Change Quarter");
    ll.addView(tv);
    ll.addView(b);
    ll.setPadding(10, 10, 10, 10);
    b.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            AlertDialog.Builder changeQuarter = new AlertDialog.Builder(SettingsActivity.this);
            changeQuarter.setTitle("Change Quarter");
            changeQuarter.setMessage("Select New Quarter");
            final RadioButton ld = new RadioButton(SettingsActivity.this);
            ld.setText("20121");
            ld.setId(1);
            final RadioButton s = new RadioButton(SettingsActivity.this);
            s.setText("20122 (Current)");
            s.setId(2);
            final RadioButton d = new RadioButton(SettingsActivity.this);
            d.setText("20123");
            d.setId(3);
            final RadioGroup rg = new RadioGroup(SettingsActivity.this);
            rg.addView(ld);
            rg.addView(s);
            rg.addView(d);
            changeQuarter.setView(rg);

            changeQuarter.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub
                }

            });
            changeQuarter.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String q;
                    int n = rg.getCheckedRadioButtonId();
                    if (n == 1)
                        q = "20121";
                    else if (n == 2)
                        q = "20122";
                    else
                        q = "20123";
                    SharedPreferences.Editor edit = sp.edit();
                    edit.putString("quarter", q);
                    edit.commit();
                    SettingsActivity.this.finish();
                }
            });

            changeQuarter.show();
        }

    });

}

From source file:com.odoo.base.login_signup.SyncWizard.java

private void generateLayout() {

    LinearLayout layout = (LinearLayout) rootView.findViewById(R.id.layoutLoginConfig);
    SyncWizardValues syncValues = new SyncWizardValues();
    List<SyncValue> syncValuesList = syncValues.syncValues();
    if (syncValuesList.size() == 0) {
        getActivity().finish();//from  w ww.  j a v  a2s.  c  o m
        getActivity().startActivity(getActivity().getIntent());
    }
    checkbox = new CheckBox[syncValuesList.size()];
    rdoGroups = new RadioGroup[syncValuesList.size()];
    TextView[] txvTitles = new TextView[syncValuesList.size()];
    int i = 0;
    int id = 1;
    Typeface tf_light = Typeface.create("sans-serif-light", 0);
    Typeface tf_bold = Typeface.create("sans-serif-condensed", 0);
    for (SyncValue value : syncValuesList) {
        if (!value.getIsGroup()) {
            if (value.getType() == SyncValue.Type.CHECKBOX) {
                checkbox[i] = new CheckBox(scope.context());
                checkbox[i].setId(id);
                checkbox[i].setText(value.getTitle());
                checkbox[i].setTypeface(tf_light);
                layout.addView(checkbox[i]);
            } else {
                rdoGroups[i] = new RadioGroup(scope.context());
                rdoGroups[i].setId(i + 50);
                RadioButton[] rdoButtons = new RadioButton[value.getRadioGroups().size()];
                int mId = 1;
                int j = 0;
                for (SyncValue rdoVal : value.getRadioGroups()) {
                    rdoButtons[j] = new RadioButton(scope.context());
                    rdoButtons[j].setId(mId);
                    rdoButtons[j].setText(rdoVal.getTitle());
                    rdoButtons[j].setTypeface(tf_light);
                    rdoGroups[i].addView(rdoButtons[j]);
                    mId++;
                    j++;
                }
                layout.addView(rdoGroups[i]);
            }
            authorities.put(id + "", value.getAuthority());
            i++;
            id++;
        } else {
            txvTitles[i] = new TextView(scope.context());
            txvTitles[i].setId(id);
            txvTitles[i].setText(value.getTitle());
            txvTitles[i].setAllCaps(true);
            txvTitles[i].setPadding(0, 5, 0, 3);
            txvTitles[i].setTypeface(tf_bold);
            layout.addView(txvTitles[i]);
            View lineView = new View(scope.context());
            lineView.setBackgroundColor(Color.parseColor("#BEBEBE"));
            lineView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 1));
            layout.addView(lineView);
        }
    }
}

From source file:com.astuetz.PagerSlidingTabStripWithStyle.java

public PagerSlidingTabStripWithStyle(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);/*ww  w  . j  a v a  2s.  c  o  m*/
    setWillNotDraw(false);

    tabsContainer = new RadioGroup(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.cs.widget.tab.PagerSlidingTabStrip1.java

public PagerSlidingTabStrip1(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);//from  w  ww  .j  a  v a 2  s  . c om
    setWillNotDraw(false);

    tabsContainer = new RadioGroup(context);
    tabsContainer.setOrientation(RadioGroup.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    tabsContainer.setPadding(0, 20, 0, 10);
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_android_textSize, tabTextSize);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_android_textColor, tabTextColor);
    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);
    lineGravity = a.getInt(R.styleable.PagerSlidingTabStrip_pstsLineGravity, lineGravity);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new RadioGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.trimph.toprand.trimphrxandroid.trimph.ui.main.news.view.PagerSlidingTabStrip.java

public PagerSlidingTabStrip(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setFillViewport(true);//  w  w w  .  j av a  2s. c om
    setWillNotDraw(false);

    tabsContainer = new RadioGroup(context);

    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setGravity(Gravity.CENTER_VERTICAL);
    removeAllViews();
    addView(tabsContainer, 0, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    tabTextSize = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTextSize, tabTextSize);
    tabTextColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsTextColor, tabTextColor);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new RadioGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new RadioGroup.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.lokiy.widget.BannerView.java

public BannerView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BannerView);
    isShowIndicator = a.getBoolean(R.styleable.BannerView_showIndicator, true);
    mIndicatorId = a.getResourceId(R.styleable.BannerView_indicator, 0);
    isCorner = a.getBoolean(R.styleable.BannerView_corner, false);
    mRectRoundRadius = a.getDimensionPixelOffset(R.styleable.BannerView_cornerRadii, 0);
    mPageMargin = a.getDimensionPixelSize(R.styleable.BannerView_pageMargin, 0);
    int mIndicatorGravity = a.getInt(R.styleable.BannerView_indicator_gravity,
            Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
    a.recycle();//  w w w .  ja  v  a2s .c  o  m
    mViewPager = new XViewPager(getContext(), null);
    mViewPager.setPageMargin(mPageMargin);
    setClipChildren(false);
    mAdapter = new BannerAdapter();
    //noinspection deprecation
    mViewPager.setOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {
        }

        @Override
        public void onPageSelected(int position) {
            position = position % mAdapter.getRealCount();
            if (isShowIndicator) {
                vRadioGroup.check(position);
            }
            if (onPageSelectedListener != null) {
                onPageSelectedListener.onPageSelected(position, mAdapter.mBannerList.get(position));
            }
        }

        @Override
        public void onPageScrollStateChanged(int position) {
        }
    });
    mViewPager.setAdapter(mAdapter);
    addView(mViewPager, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

    if (isShowIndicator) {
        vRadioGroup = new RadioGroup(getContext());
        LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        params.gravity = mIndicatorGravity;
        vRadioGroup.setGravity(Gravity.CENTER);
        vRadioGroup.setOrientation(LinearLayout.HORIZONTAL);
        addView(vRadioGroup, params);
    }
}

From source file:odoo.controls.OSelectionField.java

private void createRadioGroup() {
    final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    if (mRadioGroup == null) {
        mRadioGroup = new RadioGroup(mContext);
        mRadioGroup.setLayoutParams(params);
    } else {//  w ww  . j a  v  a 2  s  . c  o  m
        removeView(mRadioGroup);
    }
    mRadioGroup.removeAllViews();
    mRadioGroup.setOnCheckedChangeListener(this);
    for (ODataRow label : items) {
        RadioButton rdoBtn = new RadioButton(mContext);
        rdoBtn.setLayoutParams(params);
        rdoBtn.setText(label.getString(mModel.getDefaultNameColumn()));
        if (textSize > -1) {
            rdoBtn.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        }
        if (appearance > -1) {
            rdoBtn.setTextAppearance(mContext, appearance);
        }
        rdoBtn.setTextColor(textColor);
        mRadioGroup.addView(rdoBtn);
    }
    addView(mRadioGroup);
}

From source file:com.cairoconfessions.MainActivity.java

public void report(View view) {

    final EditText edit = new EditText(this);
    final RadioGroup choices = new RadioGroup(this);
    edit.setText("I would like to report this confession");
    final String[] selectedItem = getResources().getStringArray(R.array.report_choices);

    for (int i = 0; i < selectedItem.length; i++) {
        RadioButton choice = new RadioButton(this);
        choice.setText(selectedItem[i]);
        choices.addView(choice);/*  w  w  w.  j a v  a 2 s. c  om*/
    }
    choices.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // checkedId is the RadioButton selected
            edit.setText("I would like to report this confession as "
                    + ((RadioButton) group.findViewById(checkedId)).getText().toString());

        }
    });
    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    ll.addView(choices);
    ll.addView(edit);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Choose which categories:").setView(ll)
            .setPositiveButton(R.string.send, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User clicked OK button
                    reportReceived();
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    // User clicked Cancel button
                }
            }).show();
}

From source file:com.java2s.intents4.IntentsDemo4Activity.java

void addRow(final LinearLayout layout, String label, String hintStr, boolean addRadioGroup) {
    LinearLayout.LayoutParams rowLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    LinearLayout.LayoutParams editTextLayoutParams = new LinearLayout.LayoutParams(400,
            LinearLayout.LayoutParams.WRAP_CONTENT, 1);
    if (addRadioGroup) {
        editTextLayoutParams = new LinearLayout.LayoutParams(400, LinearLayout.LayoutParams.WRAP_CONTENT, 1);
    }/* www  . j  av  a  2 s.  c  o  m*/
    LinearLayout.LayoutParams buttonLayoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 0);

    LinearLayout row = new LinearLayout(this);
    row.setOrientation(LinearLayout.HORIZONTAL);
    row.setGravity(Gravity.CENTER_VERTICAL);

    TextView textView = new TextView(this);
    textView.setText(label);
    row.addView(textView);
    EditText editText = new EditText(this);
    editText.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12);
    editText.setHint(hintStr);
    editText.setLayoutParams(editTextLayoutParams);
    if (!isFirstTime) {
        editText.requestFocus();
    }
    row.addView(editText);

    if (addRadioGroup) {
        LinearLayout groupLayout = new LinearLayout(this);
        groupLayout.setOrientation(LinearLayout.VERTICAL);
        groupLayout.setGravity(Gravity.CENTER_HORIZONTAL);

        RadioGroup group = new RadioGroup(this);
        group.setLayoutParams(new RadioGroup.LayoutParams(RadioGroup.LayoutParams.WRAP_CONTENT,
                RadioGroup.LayoutParams.WRAP_CONTENT));

        final Button patternButton = new Button(this);
        patternButton.setText(pathPatterns[0]);
        patternButton.setTextSize(8);
        patternButton.setLayoutParams(buttonLayoutParams);
        patternButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                String patternButtonText = patternButton.getText().toString().trim();
                if (patternButtonText.equals(pathPatterns[0])) {
                    patternButton.setText(pathPatterns[1]);
                } else if (patternButtonText.equals(pathPatterns[1])) {
                    patternButton.setText(pathPatterns[2]);
                } else if (patternButtonText.equals(pathPatterns[2])) {
                    patternButton.setText(pathPatterns[0]);
                }
            }
        });
        groupLayout.addView(patternButton);
        row.addView(groupLayout);
    }
    Button button = new Button(this);
    button.setTextSize(10);
    button.setTypeface(null, Typeface.BOLD);
    button.setText("X");
    button.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
    button.setLayoutParams(buttonLayoutParams);
    button.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            layout.removeView((LinearLayout) view.getParent());
        }
    });
    row.addView(button);

    row.setLayoutParams(rowLayoutParams);
    layout.addView(row);
}