Android User Preference Change

My custom settings class helps me choose a color.
Custom settings call the GridView Intent, which includes 9 colors.
But My custom class cannot update the color selected by the user in gridview.

When I finish setting the preferences, restart the setting,
Color shows me how I selected.

onBindView()I redefined. It's perfect.
But I do not know which method I should change in order to update the color.

enter image description here


public class ConfigImage extends Preference
{
    Context mContext;

    public ConfigImage(Context context, AttributeSet attrs)
    {
        this(context, attrs, 0);
        this.mContext = context;
    }

    public ConfigImage(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        this.mContext = context;
        setLayoutResource(R.layout.preference_image);
    }

    @Override
    public void onBindView(View view)
    {
        super.onBindView(view);
        ImageView imageView = (ImageView) view.findViewById(R.id.preference_image_iv_color);
        if (imageView != null)
        {
            SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(mContext);
            int colorIndex = sharedPref.getInt("setting_color_default", 3);
            imageView.setBackgroundColor(Color.parseColor(ColorStorage.colors[colorIndex]));
        }
    }
}

,

    <PreferenceCategory
    android:key="setting_color_info"
    android:title="색상" >

    <com.pack.ConfigImage
        android:id="@+id/setting_color_default"
        android:key="setting_color_default"
        android:selectable="true"
        android:summary="Choose default color"
        android:title="Default Color"
        settings:background="#FFFFFFFF" />
</PreferenceCategory>
+3
source share
1 answer

Assuming your problem does not receive a notification of a change in general preference, you should subscribe to it as

registerOnSharedPreferenceChangeListener(this);
0
source

All Articles