I want to get the text from RadioButton which is Male or Female but however I got the result nullPointerExeception. Below is my code:
sex = (RadioGroup)v.findViewById(R.id.radioGroup);
int selectSex = sex.getCheckedRadioButtonId();
radioButton = (RadioButton)v.findViewById(selectSex);
String empSex = radioButton.getText().toString();
Toast.makeText(getContext(),empSex + "",Toast.LENGTH_LONG).show();
XML:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/radioGroup"
android:layout_margin="5dp"
android:orientation="horizontal"
android:weightSum="1">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/male"
android:id="@+id/maleRadio"
android:textColor="@color/colorAccent"
android:layout_weight="0.3"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/female"
android:id="@+id/femaleRadio"
android:textColor="@color/colorAccent"
android:layout_weight="0.3"/>
</RadioGroup>
PS: This is in Fragment page.