android


Get values from multiple RadioGroups


I am creating an activity which contains 7 RadioGroups each with 5 RadioButtons. My problem is that I am getting selected index of only one RadioGroup (lvl_mon) and the other 6 are returning -1 however they are selected. My code is :
lvl_mon = (RadioGroup)findViewById(R.id.lvl_monday);
lvl_tue = (RadioGroup)findViewById(R.id.lvl_tuesday);
lvl_wed = (RadioGroup)findViewById(R.id.lvl_wednesday);
lvl_thu = (RadioGroup)findViewById(R.id.lvl_thursday);
lvl_fri = (RadioGroup)findViewById(R.id.lvl_friday);
lvl_sat = (RadioGroup)findViewById(R.id.lvl_saturday);
lvl_sun = (RadioGroup)findViewById(R.id.lvl_sunday);
int index_mon = lvl_mon.indexOfChild(findViewById(lvl_mon.getCheckedRadioButtonId()));
int index_tue = lvl_tue.indexOfChild(findViewById(lvl_tue.getCheckedRadioButtonId()));
int index_wed = lvl_wed.indexOfChild(findViewById(lvl_wed.getCheckedRadioButtonId()));
int index_thu = lvl_thu.indexOfChild(findViewById(lvl_thu.getCheckedRadioButtonId()));
int index_fri = lvl_fri.indexOfChild(findViewById(lvl_fri.getCheckedRadioButtonId()));
int index_sat = lvl_sat.indexOfChild(findViewById(lvl_sat.getCheckedRadioButtonId()));
int index_sun = lvl_sun.indexOfChild(findViewById(lvl_sun.getCheckedRadioButtonId()));
If you have buttons inside of your radio groups then you can do the following:
RadioGroup lvl_mon = (RadioGroup) findViewById(R.id.lvl_monday);
String selected_mon = ((RadioButton) findViewById(lvl_mon .getCheckedRadioButtonId())).getText().toString();
Have you tried like this
lvl_mon = (RadioGroup)findViewById(R.id.lvl_monday);
RadioButton lvl_mon1;
lvl_mon.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
lvl_mon1= (RadioButton)findViewById(checkedId);
switch(checkedId){
case R.id.radio0:
// do somthings
break;
case R.id.radio1:
.......
}
}
});
int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();
View radioButton = radioButtonGroup.findViewById(radioButtonID);
int idx = radioButtonGroup.indexOfChild(radioButton);
This may help!!
I figured out the problem , I had same ids of RadioButtons in each RadioGroup so I changed the ids plus cleaned the project. This fixed the issue

Related Links

allow access to devices not asked, in one plus 2 phone, when downloading app from google store
Android - Listening to a locale change without static variables
Printing strings on screen
Back Button (activity) Return To Fragment
How to change icon and gravity of Navigation Drawer?
Capture image on current drawing state
ANDROID_HOME not set (VSTS agent running as service on OS X)
How can I override uses-feature and uses-permission
Get a TextView in an AsyncTask - Android
App is not running, showing error A/libc: Fatal signal 11 (SIGSEGV) at 0x00000e20 (code=1), thread 8068
How can I create a Location in an android Unit-Test?
drawing cache returns the same Image
File Modification check on Android
How to change font in android studio 2.1.1?
Opening a child dialog that overrides parent dialog dimension
After implementing text watcher I am getting only first Character of the String in textview?

Categories

HOME
batch-file
phantom-dsl
twitter-bootstrap-3
paraview
c++11
linkedin
rdbms
nunit
formal-languages
numbers
vscode-extensions
telegram-bot
regular-language
mapbox
gluon-mobile
boto3
p2p
jquery-ui-sortable
endeca
line
internationalization
mathprog
feathersjs
vuejs
video-editing
production
nodemcu
enterprise-miner
lilypond
microsoft-ocr
ember-cli
angular-routing
resourcebundle
ckfinder
slidetoggle
corpus
firebase-analytics
handler
angular-translate
datastax-enterprise-graph
rselenium
sessionstorage
xdocreport
z-notation
verifiable-c
linqpad
lpsolve
pom.xml
xbmc
page-replacement
payara-micro
skin
java-websocket
baidu
stripe-connect
ng-grid
tooleap
cda
fuzzywuzzy
np-spring
jbase
avisynth
extjs-grid
finalbuilder
haskell-warp
dnssec
user-permissions
cross-join
infosphere-spl
jama
jqmodal
angular-carousel
alternate
ray
conditionaltagsupport
accesscontrolexception
scriptaculous
rolify
windows-98
twisted.web
alice
os.system
correlated-subquery
window-decoration
wiimote
stress
cgimage
winmain
exponentiation
commerceserver2007
maven-1
aspmenu
hbm2java
folding
web-application-project
perl5.12
fault-tolerance
sqlobject
pbcopy

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App