Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android RadioButton IsSelected is not working

Tags:

android

I have a radio group defined with two buttons for black and color. When I try to do a calculation based on the selection nothing happens. Any idea why my radio buttons arent' working? Thanks

                public void onClick(View v) {
                // TODO Auto-generated method stub
                EditText startingAmt = (EditText) findViewById(R.id.editText1);
                RadioButton black = (RadioButton) findViewById(R.id.radio0);
                RadioButton color = (RadioButton) findViewById(R.id.radio1);
                if(!TextUtils.isEmpty(startingAmt.getText().toString().trim())){


                TextView ***** = (TextView)findViewById(R.id.textView1);
                double  temp1 = 0.0,
                        endAmt = 0.0,
                        startAmt = 0.0;
                String answer;
                Editable editableValue1 = startingAmt.getText();
                startAmt = Double.parseDouble(editableValue1.toString());
                if(color.isSelected()){
                    temp1 = startAmt * 1.15;
                    endAmt = temp1 * .15;
                    endAmt = (double)Math.round(endAmt*10)/10;
                }
                if(black.isSelected()){
                    temp1 = startAmt * 1.10;
                    endAmt = temp1 * .10;
                    endAmt = (double)Math.round(endAmt*10)/10;
                }
like image 590
Intelwalk Avatar asked Dec 05 '25 19:12

Intelwalk


2 Answers

Instead using isSelected() go for isChecked().

like image 172
Mohammed Azharuddin Shaikh Avatar answered Dec 08 '25 10:12

Mohammed Azharuddin Shaikh


Use the method isChecked instead of isSelected. Or you can use the getCheckedRadioButtonId on your RadioGroup that contains the two RadioButtons.

like image 42
user Avatar answered Dec 08 '25 10:12

user



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!