Fix bug 5205275 - SwitchPreference doesn't allow Switch to slide back
and forth. Also have the SwitchPreference's Switch widget's onClick listener toggle the switch rather than invoke the preference's own onClick method. This will allow subclasses to assign different behavior to clicking the preference itself if desired. Change-Id: I97e3b7a786e9f0e8bdc03c0ed6001caa7dcd991b
This commit is contained in:
@@ -41,14 +41,16 @@ public class SwitchPreference extends TwoStatePreference {
|
||||
private CharSequence mSwitchOff;
|
||||
private final Listener mListener = new Listener();
|
||||
|
||||
private class Listener implements View.OnClickListener, CompoundButton.OnCheckedChangeListener {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
SwitchPreference.this.onClick();
|
||||
}
|
||||
|
||||
private class Listener implements CompoundButton.OnCheckedChangeListener {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (!callChangeListener(isChecked)) {
|
||||
// Listener didn't like it, change it back.
|
||||
// CompoundButton will make sure we don't recurse.
|
||||
buttonView.setChecked(!isChecked);
|
||||
return;
|
||||
}
|
||||
|
||||
SwitchPreference.this.setChecked(isChecked);
|
||||
}
|
||||
}
|
||||
@@ -111,12 +113,6 @@ public class SwitchPreference extends TwoStatePreference {
|
||||
switchView.setTextOff(mSwitchOff);
|
||||
switchView.setOnCheckedChangeListener(mListener);
|
||||
}
|
||||
|
||||
if (checkableView.hasFocusable()) {
|
||||
// This is a focusable list item. Attach a click handler to toggle the button
|
||||
// for the rest of the item.
|
||||
view.setOnClickListener(mListener);
|
||||
}
|
||||
}
|
||||
|
||||
syncSummaryView(view);
|
||||
|
||||
@@ -22,5 +22,4 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:padding="16dip"
|
||||
android:focusable="false"
|
||||
android:clickable="false" />
|
||||
android:focusable="false" />
|
||||
|
||||
Reference in New Issue
Block a user