问题描述
我已经建立无线电集团,自定义布局,即自定义按钮。
I have created radio group with custom layout i.e. custom button.
<?xml version="1.0" encoding="utf-8"?>
<RadioGroup
android:id="@+id/radio_group_rating"
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3" >
<RadioButton
android:id="@+id/radio_platinum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:clickable="true"
android:drawablePadding="10dp"
android:drawableTop="@drawable/star_small_dis"
android:gravity="center"
android:text="@string/platinum" />
<RadioButton
android:id="@+id/radio_gold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:clickable="true"
android:drawablePadding="10dp"
android:drawableTop="@drawable/star_small_dis"
android:gravity="center"
android:text="@string/gold" />
<RadioButton
android:id="@+id/radio_silver"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:clickable="true"
android:drawablePadding="10dp"
android:drawableTop="@drawable/star_small_dis"
android:gravity="center"
android:text="@string/silver" />
</LinearLayout>
</RadioGroup>
<Button
android:id="@+id/btn_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="@id/radio_group_rating"
android:text="@string/submit" />
和的活动,我有以下code,
And in Activity, I have below code,
final Dialog dialog = new Dialog(mActivity);
dialog.setContentView(R.layout.rating_cust_dialog_layout);
radioGroupRating = (RadioGroup) dialog.findViewById(R.id.radio_group_rating);
Button btnSubmit = (Button) dialog.findViewById(R.id.btn_submit);
btnSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
int selectedRadioId = radioGroupRating.getCheckedRadioButtonId();
View radioButton = radioGroupRating.findViewById(selectedRadioId);
Integer selctedPosition = radioGroupRating.indexOfChild(radioButton);
dialog.dismiss();
}
});
dialog.show();
我的问题是单选按钮都没有获得点击。我认为这是由于Android的:按钮=@空
所以,我与机器人取代了它:键=@可绘制/ star_dis
,但仍然没有得到点击。
My issue is radio buttons are not getting clicked. I thought it's because of android:button="@null"
So I replaced it with android:button="@drawable/star_dis"
but still not getting clicked.
推荐答案
唯一的区别我的code是我不把点击=真正的
在XML中,如果 RadioGroup中
自行处理触摸事件来管理孩子单选按钮,你应该删除该属性可点击一般设置为true时,将自动设置 OnClickListener
。
Only difference to my code is that I don't put clickable="true"
in xml, if RadioGroup
handles touch event by itself to manage child radio buttons you should remove that attribute as clickable is generally set to true automatically when you set an OnClickListener
.
这篇关于安卓定制的单选按钮没有得到检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!