我已經創建了自定義佈局即自定義按鈕的廣播組。android自定義單選按鈕沒有被檢查
<?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" />
而在活動,我有下面的代碼,
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:button="@null"
所以我用android:button="@drawable/star_dis"
替換它,但仍然沒有得到點擊。
感謝您的幫助@Divya,但我想要完全相同的設計。所以我想現在我必須處理查看點擊並寫我自己的邏輯:( – 2015-01-21 05:48:44
我認爲剛剛刪除android:button =「@ null」,應該解決問題。高興地幫助:) – 2015-01-21 06:13:42
沒有親愛的...之後刪除它,點擊工程,但單選按鈕的默認圓圈開始出現......即回到原點:) – 2015-01-21 08:42:24