Radio button in android studio | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Radio button in android studio

I have created 5 radio buttons and trying to display the total number of radio buttons I have selected but the app is getting crash. I may be due to use of count++ because if I don't use count++ and just display a toast it is working fine. https://code.sololearn.com/c3lEqSOXMIGY/?ref=app

20th Jan 2019, 9:31 PM
harshit
harshit - avatar
5 Answers
+ 2
You must have a reference to radiobuttons before using them... Something like: RadioButton r1 = findViewById(R.id.<id of radiobutton 1>);
21st Jan 2019, 3:42 AM
unChabon
unChabon - avatar
+ 2
Hi! Probably you want to put your RadioButtons inside a RadioGroup... look at this document: https://docs.google.com/presentation/d/e/2PACX-1vQQOSFfWksA_o3KAPOZQL3dDADS2emVcDIizeHwYYXGwsTkY2QIboqiFp2GU6Iy_iaoVv_K3933cSU3/pub?start=false&loop=false&delayms=10000 Look at slides 13..15 (In spanish... sorry :) ) - or you must add a listener for every radiobutton... ...hope that helps.. :)
21st Jan 2019, 3:51 PM
unChabon
unChabon - avatar
+ 1
Yes I have already created all of them. That's what I am saying, in the If statement if I try to print a Toast it is working but if I try to do an arithmetic operation like count++ the app gets crashing.
21st Jan 2019, 5:33 AM
harshit
harshit - avatar
+ 1
hussein [OFFLINE] can you please look at this
21st Jan 2019, 8:56 AM
harshit
harshit - avatar
0
Thanks, I have assigned a listener for every radio button and my problem is solved.
22nd Jan 2019, 6:59 AM
harshit
harshit - avatar