views:

87

answers:

1

I have a Preference that enables a sync adapter, and takes a while to actually do its work when toggled. Consequently, when the user clicks the Preference, I spin off an AsyncTask to do the work. In the meantime, I disable the Preference and replace the check box with an indeterminate ProgressBar. I have all of this working via a hack involving a subclass of CheckBoxPreference that overlays the ProgressBar on top of the CheckBox. Yuck.

The android:widgetLayout attribute seems like it's designed exactly for this. I should be able to use android:widgetLayout to specify a replacement for the default CheckBox. Said replacement would implement Checkable and use a ViewSwitcher to switch appropriately between a CheckBox and a ProgressBar.

The only problem is that CheckBoxPreference, in its onBindView() method, seems to ignore the possibility that android:widgetLayout may be used. It explicitly does this:

View checkboxView = view.findViewById(com.android.internal.R.id.checkbox);

This effectively makes it impossible to swap in a custom Checkable via android:widgetLayout and have it actually work.

Is this an oversight/bug in CheckBoxPreference, or have I misunderstood android:widgetLayout? Is there a cleaner intended way to do what I'm trying to do?

A: 

android:widgetLayout is the right part of the preference. In the CheckBoxPreference, the widgetLayout is the checkbox. If you take a base Preference and put a ViewSwitcher in the widgetLayout, it should work

fedj
Sure, but then I miss out on the stuff CheckBoxPreference does, like summaries and accessibility.
loganj