【发布时间】:2018-05-31 05:27:11
【问题描述】:
我想禁用对放置在相对布局内的 RadioGroup 的点击!在某种程度上,我唯一的相对布局应该是可点击的。我希望在某些特定条件下我的 XML 如下:
<RelativeLayout
android:id="@+id/shouldNotPlayLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="40dp"
android:layout_marginLeft="44dp"
android:layout_marginRight="44dp"
android:layout_marginTop="40dp">
<RadioGroup
android:id="@+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:saveEnabled="false">
<RadioButton
android:id="@+id/radio_option_a"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/radio_option_selector"
android:button="@null"
android:padding="15dp"
android:textColor="#161743"
android:textSize="14sp"
android:textStyle="normal"
tools:text="First option"/>
<RadioButton
android:id="@+id/radio_option_b"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/radio_option_selector"
android:button="@null"
android:padding="15dp"
android:textColor="#161743"
android:textSize="14sp"
android:textStyle="normal"
tools:text="First option"/>
<RadioButton
android:id="@+id/radio_option_c"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:background="@drawable/radio_option_selector"
android:button="@null"
android:padding="15dp"
android:textColor="#161743"
android:textSize="14sp"
android:textStyle="normal"
tools:text="First option"/>
</RadioGroup>
</RelativeLayout>
我正在停止对广播组的点击:
binding.questionLayout.radioOptionA.setEnabled(false);
binding.questionLayout.radioOptionB.setEnabled(false);
binding.questionLayout.radioOptionC.setEnabled(false);
binding.questionLayout.radioOptionA.setFocusable(false);
binding.questionLayout.radioOptionB.setFocusable(false);
binding.questionLayout.radioOptionC.setFocusable(false);
binding.questionLayout.shouldNotPlayLayout.requestFocus();
binding.questionLayout.shouldNotPlayLayout.setClickable(true);
binding.questionLayout.shouldNotPlayLayout.setFocusable(true);
我面临的问题是,有时这三个单选按钮中的任何一个仍然可以单击,并且用户可以单击任何单选按钮。但我想禁用对单选组/按钮的点击并在相关布局上完成点击!
谁能帮我想想我犯了什么错误?
【问题讨论】:
-
你为
binding.questionLayout.shouldNotPlayLayout添加了setOnClickListener吗?
标签: android onclicklistener android-relativelayout android-radiobutton android-radiogroup