Я хочу получить текст от RadioButton, который является Мужским или Женским, но, тем не менее, я получил результат nullPointerExeception. Ниже мой код:
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: Это на странице фрагмента.