动态生成radiobutton

//动态添加布局
        // set 文本大小
        LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(mBinding.llButtonWeight.getWidth()/result.size(),
                ViewGroup.LayoutParams.WRAP_CONTENT);
        //set 四周距离
        params1.setMargins(0, 0, 0, 0);
        params1.weight=1;
        final RadioButton[] radioButton=new RadioButton[result.size()];
        for(int i=0;i<result.size();i++){
            if(result.get(i).getCode().equals(mType)){
                radioButton[Count]=new RadioButton(mObj);
                radioButton[Count].setText(result.get(i).getSpecifications());
                radioButton[Count].setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                        int position = (int) buttonView.getTag();
                        if (isChecked) {
                            radioButton[position].setTextColor(Color.WHITE);
                        } else {
                            radioButton[position].setTextColor(Color.BLACK);
                        }
                    }
                });
                radioButton[Count].setTextColor(Color.BLACK);
                radioButton[Count].setTextSize(13);
                radioButton[Count].setGravity(Gravity.CENTER_HORIZONTAL);
                radioButton[Count].setButtonDrawable(null);
                radioButton[Count].setLayoutParams(params1);
                radioButton[Count].setTag(i);
                Count++;
            }
        }
        for(int j=0;j<Count;j++){
            if(j==0){
                radioButton[j].setBackgroundResource(R.drawable.left_specification_shape);
            }else if(j==Count-1){
                radioButton[j].setBackgroundResource(R.drawable.right_specification_shape);
            }else {
                radioButton[j].setBackgroundResource(R.drawable.common_specification_shape);
            }
            mBinding.llButtonWeight.addView(radioButton[j]);
            mBinding.llButtonWeight.check(radioButton[0].getId());
        }
        mBinding.llButtonWeight.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {

                if (ValueList.size() > 0) {
                    for (PositionValue item : ValueList) {
                        if (mType.equals(item.getCode())) {

                            RadioButton rb= (RadioButton)group.findViewById(checkedId);
                            int TagPosition = (int)rb.getTag();
                            item.setPosition(TagPosition);
                            position=TagPosition;
                            mBinding.advanceChargeShow.setText(result.get(TagPosition).getPrice()+"元");
                            mBinding.differencePriceShow.setText(VerifyUtil.trimTwoBit(result.get(TagPosition).getFuctuateAmount())+"元");
                            mBinding.serviceChargeShow.setText(VerifyUtil.trimTwoBit(result.get(TagPosition).getSellCommissionAmount()));
                            mBinding.storagePriceShow.setText(VerifyUtil.trimTwoBit(result.get(TagPosition).getStorageCommissionAmount())+"元/天");

                        }
                    }
                }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值