Open jstefanowski opened 10 years ago
I want to use this in order to inject OnCheckedChangedListener
into RadioGroup
.
+1
+1 for this
+1
+1
+1 make it better
+1
+1
+1
+1
+1
Hi, what is the status of this? By trying to @Bind(R.id.radio_group_id) RadioGroup mMyRadioGroup;
I get a android.widget.RadioGroup cannot be cast to android.widget.CompoundButton
.
@ticofab that is unrelated and sounds like you just need to clean your project.
Temporary workaround is to bind all radio buttons to the same callback and then check which is selected:
@OnClick({R.id.radio_button1, R.id.radio_button2})
public void radioGroupUpdate() {
radio1.isChecked() ? ....
}
thanks @JakeWharton and @peterbartos for your comments!
+1
+1
+1
+1
+1
+1
+1
@OnClick({ R.id.radio_pirates, R.id.radio_ninjas }) public void onRadioButtonClicked(RadioButton radioButton) {
// Is the button now checked?
boolean checked = radioButton.isChecked();
// Check which radio button was clicked
switch (radioButton.getId()) {
case R.id.radio_pirates:
if (checked) {
// Pirates are the best
}
break;
case R.id.radio_ninjas:
if (checked) {
// Ninjas rule
}
break;
}
}
+1
+1
+1
So this listener is available?Now that this issue is closed?
@manideepl but the issue is not closed...
+1
+1
+1
+1
+1
+1
+1
+1
+1
+1
+2
+1
+1
+1
+1
+1
+1
+1
This works
@OnCheckedChanged({R.id.rbt_yes, R.id.rbt_no})
public void radioButtonCheckChanged(CompoundButton v, boolean b){
// insert your code here
}
+1
@BindView(R.id.cb_msg) public CheckBox cbMsg; @BindView(R.id.cb_phone) public CheckBox cbPhone; @OnCheckedChanged() protected void onCheckedMode(CompoundButton compoundButton,boolean isChecked) { if (compoundButton==cbMsg){ mode = isChecked?mode+ BlackList.MODE_SMS_INTERCEPT:mode-BlackList.MODE_SMS_INTERCEPT; } if (compoundButton==cbPhone){ mode = isChecked?mode+BlackList.MODE_PHONE_INTERCEPT:mode-BlackList.MODE_PHONE_INTERCEPT; } } what the problem is? crashed message is com.android.internal.policy.impl.PhoneWindow$DecorView cannot be cast to android.widget.CompoundButton
Butterknife could probably also include OnCheckedChanged listener injection for RadioGroups.