【问题标题】:Radio button state not saving单选按钮状态未保存
【发布时间】:2014-10-24 02:51:07
【问题描述】:

这是我为绘制的模拟时钟显示颜色的代码,为此我使用了 rado 组并通过我的动态壁纸中的共享偏好使用它,我点击的任何颜色都成功应用于时钟,但问题是关闭后再次返回颜色选择窗口时没有保存以前的单选按钮状态,请任何人帮我纠正错误

protected void onDialogClosed(boolean flag) {
    flag1=flag;
    super.onDialogClosed(flag1);
    if (flag1) {
        android.content.SharedPreferences.Editor editor = getEditor();
        saveRadioButton(editor, 0x7f080001, 0xffffff);
        saveRadioButton(editor, 0x7f080002, 0xc0c0c0);
        saveRadioButton(editor, 0x7f080003, 0x808080);
        saveRadioButton(editor, 0x7f080004, 0xff0000);
        saveRadioButton(editor, 0x7f080005, 0xff8000);
        saveRadioButton(editor, 0x7f080006, 0xffff00);
        saveRadioButton(editor, 0x7f080007, 0x80ff00);
        saveRadioButton(editor, 0x7f080008, 65280);
        saveRadioButton(editor, 0x7f080009, 65408);
        saveRadioButton(editor, 0x7f08000a, 65535);
        saveRadioButton(editor, 0x7f08000b, 33023);
        saveRadioButton(editor, 0x7f08000c, 255);
        saveRadioButton(editor, 0x7f08000d, 0x8000ff);
        saveRadioButton(editor, 0x7f08000e, 0xff00ff);
        saveRadioButton(editor, 0x7f08000f, 0xff0080);
        editor.commit();
    }
}

protected void saveRadioButton(android.content.SharedPreferences.Editor editor, int i, int j) {

    if (((RadioButton)mainView.findViewById(i)).isChecked()) {
        editor.putInt(getKey(), j);
    }

}

【问题讨论】:

    标签: android sharedpreferences radio-group


    【解决方案1】:

    不需要写这么多的方法调用,view.getId() 会返回特定的 id,你只需要在 SharedPreferences 中保存值。你应该在适当的地方从 SharedPreferences 中获得价值。

    【讨论】:

      【解决方案2】:

      之后尝试拨打editor.commit();

      editor.putInt(getKey(), j);
      editor.commit();
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多