私はxmlファイル内のラジオボタンと無線グループを持っている:AndroidでラジオボタンをIDで探す方法は?
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/btn_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:id="@+id/btn_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="onRadioButtonClicked" />
</RadioGroup>
は、どのように私はidで、ラジオボタンを得ることができますか?私が試した:
RadioButton btn = (RadioButton)findViewById(R.id.btn_1)
をしかし、私はbtn
にsetChecked()
メソッドを呼び出すときに、これは、NullPointerExceptionがスローされます。私は何か見落としてますか?
のRadioButton BTN =(ラジオボタン)findViewById(R.id.btn_1) –