I am using SwitchPreference but it seems that only clicking on the preference view(row) triggers either preference click listener or preference change listener. After clicking the switch itself the listeners don't get called even though the switch state changes.
Is there anything to be done about this?
EDIT: I figured something out. This is my listener:
switchPref.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
//not called when clicking preference itself
return true;
}
});
And this is my SwitchPreference:
<SwitchPreference
android:key="@string/key_email_messages"
android:layout="@layout/prefs_switch"
android:title="@string/title_email_messages" />
I am using a custom layout to change font size of the preference.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/viewWrap"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/prefs_row_padding">
<TextView
android:id="@android:id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/pref_text_size" />
<Switch
android:id="@+id/switch_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true" />
</RelativeLayout>
I'm guessing SwitchPreference doesn't find the switch with that id. What id I'm supposed to use?