Skip to content

Instantly share code, notes, and snippets.

@Gnzlt
Created February 22, 2017 12:24
Show Gist options
  • Save Gnzlt/70bb82e91a90d240e8d78e5a8ff49c3b to your computer and use it in GitHub Desktop.
Save Gnzlt/70bb82e91a90d240e8d78e5a8ff49c3b to your computer and use it in GitHub Desktop.
Android check box preference with check box replaced by radio button
<?xml version="1.0" encoding="utf-8"?>
<!-- Layout used by CheckBoxPreference for the checkbox style. This is inflated
inside android.R.layout.preference. -->
<RadioButton android:id="@+android:id/checkbox"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:clickable="false"
android:focusable="false"/>
public class RadioButtonPreference extends CheckBoxPreference {
public RadioButtonPreference(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
setWidgetLayoutResource(R.layout.preference_widget_radiobutton);
}
public RadioButtonPreference(Context context, AttributeSet attrs) {
super(context, attrs);
setWidgetLayoutResource(R.layout.preference_widget_radiobutton);
}
public RadioButtonPreference(Context context) {
this(context, null);
}
@Override
public void onClick() {
if (this.isChecked()) {
return;
}
super.onClick();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment