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

Android - App locale changes and displayed orientation
Android RelativeLayout Background Color
How to decode string to UTF-8 correctly? [closed]
Widget is not appearing in widget laucher section
Set a Margin between two buttons programmatically from a linearlayout
Android: Custom CursorAdapter to alternate resources
Qt Creator: No valid kits for Android found
How to annotation order field when using XStream on Android?
Layout Resize when keyboard appear (ScrollView)
Android Webview memory increases
Out of Memory Exception - Google Map GroundOverLay
How to calculate area of Irregular polygon drawn on map fragment using Google map API V2 in android? [duplicate]
how to start a service in android
Get google apis in unsupported mobiles?
Send commands to android app from server
Inserting into SQLITE in cocos2d-x

Categories

HOME
fabricjs
google-cloud-platform
time-complexity
pagination
jsf-2.2
can
cakephp-3.4
hpc
mapbox
character
ibeacon-android
text-mining
plist
openbugs
tput
pybossa
shared-libraries
http-post
job-scheduling
connector
solrcloud
libigl
aggregation
xunit
surveymonkey
jquery-multiselect
outliers
handler
sinch
uitapgesturerecognizer
dst
paragraph
fstream
navigator
salesforce-communities
metaprogramming
apache-stanbol
comparison-operators
laravel-elixir
naming
ssrs-2014
importerror
apache-spark-dataset
monkey-testing
flask-restful
getchar
openresty
yii2-api
zenhub
semantic-logging
check-mk
polyline
choice
simplepie
xcode-server
google-cloud-console
tinkerpop3
phpwebsocket
html-to-pdf
fuzzywuzzy
nupic
jbase
inf
boomerang
dynatree
wiredep
rate-limiting
zen-cart
doctype
skspritenode
ms-access-2000
jquery-forms-plugin
qtwebengine
mass-assignment
beatsmusic
administration
spy++
mobility
authlogic
xmltodict
ora-06550
bin
notorm
script#
jquery-1.9
video-codecs
mysql-error-2013
robotlegs
jquery-blockui
xcode3.2
fusefabric
httponly
failing-tests
ilasm
jsr286
jquery-address
relative
promotion-code
android-holo-everywhere
undefined-index
burndowncharts
purepdf
scrubyt
linfu-dynamicproxy

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