我有一个API,并且有一个广播的值,选项是公共的,私有的,登录的和不公开的。如果广播是公开的,我希望将radiobutton本身选为公共。
这是我的XML代码:
<TextView
android:textColor="#060606"
android:layout_marginTop="10dp"
android:textSize="15sp"
android:text="Broadcast Options"
android:id="@+id/broadcast_head"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:orientation="vertical"
android:id="@+id/radio_group_broadcast"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:textSize="16sp"
android:text="Public"
android:id="@+id/radio_button_public"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:textSize="16sp"
android:text="Private"
android:id="@+id/radio_button_private"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:textSize="16sp"
android:text="Unlisted"
android:id="@+id/radio_button_unlisted"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioButton
android:textSize="16sp"
android:text="Logged Only"
android:id="@+id/radio_button_logged_only"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RadioGroup>
</TextView>
这是我的Java代码; 我不知道这段代码是否正确。
rbPub = (RadioButton)findViewById(R.id.radio_button_public);
rbPri = (RadioButton)findViewById(R.id.radio_button_private);
rbUnl = (RadioButton)findViewById(R.id.radio_button_unlisted);
rbOnl = (RadioButton)findViewById(R.id.radio_button_logged_only);
radioGroup1 = (RadioGroup) findViewById(R.id.radio_group_broadcast);
VideoDetail videoDetailBroadcast = null; //this is the problem, can't fix(null)
if (videoDetailBroadcast.isPublic()) {
rbPub.setChecked(true);
}
else if (videoDetailBroadcast.isPrivate()) {
rbPri.setChecked(true);
}
else if (videoDetailBroadcast.isUnlisted()) {
rbUnl.setChecked(true);
}
else if (videoDetailBroadcast.isLoggedOnly()) {
rbOnl.setChecked(true);
}
答案 0 :(得分:0)
你应该以这种方式初始化videoDetailBroadcast:VideoDetail videoDetailBroadcast = new VideoDetail()