动态添加radiobutton

根据服务器返回的支付方式动态添加radiobutton

 

动态添加radiobutton_第1张图片

String[] paymode = payModeStr.split(",");
for(String string : paymode){
    RadioButton radioButton = new RadioButton(mContext);
    radioButton.setButtonDrawable(null);
    addDrawable(radioButton,string);
    //将按钮更改为在右侧
    Drawable drawable = mContext.getResources().getDrawable(R.drawable.seletor_custom_cbox);
    drawable.setBounds(0,0,50,50);
    radioButton.setCompoundDrawables(drawableLeft,null,drawable,null);
    radioButton.setTextSize(TypedValue.COMPLEX_UNIT_SP,14);
    radioButton.setTextColor(mContext.getResources().getColor(R.color.black));
    //设置id
    radioButton.setId(Integer.parseInt(string));
    RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            (int)(mContext.getResources().getDimension(R.dimen.dp_40) + 0.5f));
    layoutParams.setMargins(0,0,0,0);
    radioGroup.addView(radioButton,layoutParams);
}

你可能感兴趣的:(动态添加radiobutton)