Search code examples
androidsharedpreferencespreferences

Android preference, how to set dependancy on custom preference


I want some other preference dependent on a preference which invokes an intent 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 starts an activity which takes input from user and saves it into sharedpreference.

now my checkbox is not getting enabled or disabled based on that. I also tried adding to urlpref

android:disableDependentsState="true"

So what is the proper way to do it?


Solution

  • This is how i resolved it. What I did was register a sharedpreference listener on the item and whenever that changed i manually enabled or disabled the dependent items.