My app tracks restaurant server sales to help them on a budget. In an action showing past shifts, I created a RadioGroup under a ListView so that the user can display lunch, dinner, or both.
I implemented in the activity of RadioGroup.onCheckedChangeListener, but onCheckedChanged is never called. I also tried using an anonymous inner class as a listener, the same result.
I tried copying / changing the code from this answer: https://stackoverflow.com/a/166268/2126161 ... but when I added the @Override function to the callback function, the Eclipse compiler gave me an error (not a warning) that the method should override superclass, and the quick fix is ββto remove the override.
I am sure the signatures are consistent, as they were made with Eclipse autocomplete and implement the methods. Then I followed the instructions for moving my java compiler from 1.5 to 1.6, and none of the above actions changed.
Here is the code that I think is appropriate:
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);
There is a ListView with a custom adapter in this class, but if my understanding and my XML are correct, RadioGroup should be outside 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 there?
source share