ButterKnife RadioGroup選擇事件


ButterKnife 的點擊事件都很清晰,在使用RadioGroup控件時的方法:

           <!-- 定義一組單選框 --> <RadioGroup android:id="@+id/radio_group_sex" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" android:layout_marginRight="10dp" android:orientation="horizontal"> <!-- 定義兩個單選框 --> <RadioButton android:id="@+id/male" android:layout_width="wrap_content" android:layout_height="wrap_content" android:checked="true" android:text="男" android:textColor="@color/black" /> <RadioButton android:id="@+id/female" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="女" android:textColor="@color/black" /> </RadioGroup> 

事件如下:

 /** * 性別選中事件 * @param view * @param ischanged **/ @OnCheckedChanged({R.id.male, R.id.female}) public void onRadioCheck(CompoundButton view, boolean ischanged) { switch (view.getId()) { case R.id.male: if (ischanged) { ToastUtils.showShort("男孩子哦"); } break; case R.id.female: if (ischanged) { ToastUtils.showShort("女孩子哦"); } break; default: break; } }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM