0

I have an Activity that does the following

Button distanceSort = (Button) findViewById(R.id.distanceSortButton);
    Button waitTimeSort = (Button) findViewById(R.id.waitTimeSortButton);
    Button nameSort = (Button) findViewById(R.id.nameSortButton);
    Button mapButton = (Button) findViewById(R.id.locationsMapButton);
    Button dashboardButton = (Button)findViewById(R.id.dashboardButton);
    RadioGroup sortingGroup = (RadioGroup)findViewById(R.id.sortingRadioGroup);

and the xml is this

<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sortingRadioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/headerBar"
android:layout_centerHorizontal="true"
android:checkedButton="@+id/distanceSortButton"
android:orientation="horizontal" >

<RadioButton
    android:id="@id/distanceSortButton"
    style="@style/tabText"
    android:layout_weight="1"
    android:background="@drawable/radio_group_selector"
    android:button="@null"
    android:checked="true"
    android:gravity="center"
    android:text="@string/distance_sort_button" />

<View
    android:layout_width="1dp"
    android:layout_height="48dp"
    android:background="@drawable/tab_separator" />

<RadioButton
    android:id="@+id/waitTimeSortButton"
    style="@style/tabText"
    android:layout_weight="1"
    android:background="@drawable/radio_group_selector"
    android:button="@null"
    android:gravity="center"
    android:text="@string/wait_time_sort_button" />

<View
    android:layout_width="1dp"
    android:layout_height="48dp"
    android:background="#464646" />

<RadioButton
    android:id="@+id/nameSortButton"
    style="@style/tabText"
    android:layout_weight="1"
    android:background="@drawable/radio_group_selector"
    android:button="@null"
    android:gravity="center"
    android:text="@string/name_sort_button" />
</RadioGroup>

What my problem is that all the buttons are found, but the radio group always returns null. I want to use that RadioGroup to find out which button has been checked. Doesn't make sense to me that the buttons inside radio group can be found but the RadioGroup itself cant' be?

QuinnVT
  • 191
  • 1
  • 13
  • Are you sure it's not `distanceSortButton` returning null? You have `@id/distanceSortButton` which it should be `@+id/distanceSortButton`. – DeeV Jun 14 '12 at 20:03
  • yes. the declaration for distanceSortButton is in the radioGroup tag= `android:checkedButton="@+id/distanceSortButton"` – QuinnVT Jun 14 '12 at 20:16
  • I take it this is all part of a RelativeLayout? Also, I don't see it here, but do you have a closing for the RadioGroup item? Should be at the bottom, and I don't see it! – trumpetlicks Jun 14 '12 at 20:29
  • the snippet I shared is a separate xml that I'm including in a relative layout. – QuinnVT Jun 14 '12 at 20:31
  • apparently the fact that it was include is the cause of the problem, but that still doesn't make sense to me. But once I put the radioGroup into the main layout instead of having it as in include, then the activity was able to find it. – QuinnVT Jun 15 '12 at 14:38

0 Answers0