Android preferences on how to make user settings dependent

I want some other preference to depend on a preference that causes the intention to do some processing.

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <Preference android:key="urlpref" android:summary="summary here" android:title="title here" > <intent android:action="android.intent.action.VIEW" android:data="http://www.android.com" android:targetClass="com.example.app.popupactivity" android:targetPackage="com.example.app" /> </Preference> <CheckBoxPreference android:defaultValue="false" android:key="enablepref" android:summary="Summary" android:title="title" android:dependency="urlpref"/> 

Basically, the first preference triggers an activity that takes input from the user and stores it in a sharedpreference.

now my checkbox will not be enabled or disabled based on this. I also tried adding urlpref

 android:disableDependentsState="true" 

So what is the right way to do this?

+4
source share
1 answer

This is how I solved it. What I did was register the sharedpreference listener for the element and whenever this changed, I manually turned on or off the dependent elements.

0
source

Source: https://habr.com/ru/post/1479488/


All Articles