2014-08-30 99 views
0

這是我用於顯示繪製的模擬時鐘顏色的代碼,爲此我使用了rado組,並在我的動態壁紙中通過共享的prefence使用它,我單擊的顏色曾經成功應用於時鐘,但是當回到colorpicking窗口前面的單選按鈕狀態不保存的問題結束後,再次,任何一個可以請幫我錯誤單選按鈕狀態不存儲

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); 
    } 

} 

回答

0

無需糾正,以寫了這麼多方法調用,view.getId()會返回特定的ID,並且只有在SharedPreferences中保存值。你應該從適當的地方獲得SharedPreferences的價值。

0

嘗試調用我已經加入此editor.commit();

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

,但沒有奏效 – naveen427ch 2014-08-30 07:06:00

+0

嘗試使用RadioGroup中Checkchange聽衆,而不是單選按鈕,http://stackoverflow.com/questions/13529361/how-to -attach-A-監聽到一個無線電按鈕 – user3132107 2014-08-30 11:29:00