【问题标题】:Android Custom Preference changing OverrideAndroid 自定义首选项更改覆盖
【发布时间】:2012-04-27 18:46:33
【问题描述】:

我的自定义偏好类有助于颜色选择。
自定义首选项调用 GridView Intent 它包含 9 种颜色。
但我的自定义类无法刷新用户在 gridview 上选择的颜色

当我完成偏好意图时,然后重新启动偏好,
我选择的颜色会显示给我。

onBindView() 方法,我重写了。非常完美。
但我不知道我必须重写什么方法来刷新颜色。


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>

【问题讨论】:

    标签: android preference


    【解决方案1】:

    假设您的问题没有收到共享偏好更改的通知,那么您应该订阅它的更改

    registerOnSharedPreferenceChangeListener(this);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 2011-10-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多