RadioGroup onCheckedChanged function won't fire
Posted
by
user1758088
on Stack Overflow
See other posts from Stack Overflow
or by user1758088
Published on 2012-10-19T03:22:02Z
Indexed on
2012/10/19
5:02 UTC
Read the original article
Hit count: 201
android
|android-widget
First time/long time. My app keeps track of restaurant servers' shift sales to help them budget. In the activity that displays past shifts, I've created a RadioGroup under the ListView so the server can choose lunch, dinner, or both. I've implemented RadioGroup.onCheckedChangeListener, but onCheckChanged never gets called. I also tried an anonymous inner class as listener, same result. I tried to copy/modify code from this answer: http://stackoverflow.com/a/9595528 ...but when I added the @Override to the callback function, the Eclipse compiler gave me an error (not warning) that the method must override a superclass, and the quick fix was to remove the override. I'm pretty sure the signatures are correct, as they were made with Eclipse's autocomplete and implement methods facilities. I then followed instructions to move my java compiler from 1.5 to 1.6, and none of the above listed behavior seemed to change. Here's the code I thing is relavent:
public class DataActivity extends ListActivity implements OnCheckedChangeListener{
RadioButton rbBoth;
RadioButton rbDinnerOnly;
RadioButton rbLunchOnly;
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.database);
...
final RadioGroup rgGroup = (RadioGroup)findViewById(R.id.DataRadioGroup);
rbBoth = (RadioButton)findViewById(R.id.RadioBoth);
rbDinnerOnly = (RadioButton)findViewById(R.id.RadioDinnerOnly);
rbLunchOnly = (RadioButton)findViewById(R.id.RadioLunchOnly);
rgGroup.setOnCheckedChangeListener(this);
populateAllShifts();
}
...
public void onCheckedChanged(RadioGroup group, int checkedId) {
rbLunchOnly.setText("Click!");
Toast.makeText(getApplicationContext(), "Lunch Only", Toast.LENGTH_LONG).show();
if(group.getCheckedRadioButtonId() == R.id.RadioBoth){
populateAllShifts();
return;
}
if(group.getCheckedRadioButtonId() == R.id.RadioLunchOnly){
populatLunchShifts();
return;
}
if(group.getCheckedRadioButtonId() == R.id.RadioDinnerOnly){
populateDinnerShifts();
return;
}
}
There is a ListView in this class with a custom adapter, but if my understanding and my XML are correct, the RadioGroup should be outside of the list:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llDataLayout"
android:weightSum="5"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ListView android:layout_weight="4" android:layout_width="fill_parent" android:id="@android:id/list" android:layout_height="wrap_content"></ListView>
<RadioGroup
android:layout_weight="1" android:id="@+id/DataRadioGroup" android:orientation="horizontal" android:layout_height="wrap_content" android:layout_width="fill_parent">
<RadioButton android:text="Lunch and Dinner" android:textSize="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/RadioBoth"/>
<RadioButton android:text="Dinner Only" android:textSize="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/RadioDinnerOnly"/>
<RadioButton android:text="Lunch Only" android:textSize="10dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/RadioLunchOnly"/>
</RadioGroup>
</LinearLayout>
Any ideas out there?
© Stack Overflow or respective owner