I am using a CountDownTimer which is set by a alarm_delay_keys value:
public void arming() {
// changing system_state textview
tvSystemState = (TextView) findViewById(R.id.system_state);
tvSystemState.setText(R.string.system_state_arming);
// starting countdown
settings = getPrefs();
seconds = Integer.parseInt(settings.getString("alarm_delay_keys",
"30"));
alarmDelay = seconds * 1000;
CountDown counter = new CountDown(alarmDelay,1000);
counter.start();
}
public SharedPreferences getPrefs() {
// PreferenceManager pm = pa.getPreferenceManager();
// settings = pm.getSharedPreferences();
// settings = this.getPreferences(0);
// settings = PreferenceManager.getDefaultSharedPreferences(this);
settings = PreferenceManager.getDefaultSharedPreferences
(getBaseContext());
return settings;
}
public class CountDown extends CountDownTimer {
private TextView tvCountDown = (TextView) findViewById
(R.id.progress);
private TextView tvSystemState = (TextView) findViewById
(R.id.system_state);
public CountDown(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onFinish() {
tvSystemState.setText(R.string.system_state_armed);
tvCountDown.setText(R.string.armed);
}
@Override
public void onTick(long millisUntilFinished) {
tvCountDown.setText(millisUntilFinished/1000 + " seconds until
Armed");
}
Here's a snippet of the res/values/arrays.xml:
<string-array name="alarm_delay_keys">
<item>15 seconds</item>
<item>30 seconds</item>
<item>1 minute</item>
<item>5 minutes</item>
<item>15 minutes</item>
</string-array>
<string-array name="alarm_delay_values">
<item>15</item>
<item>30</item>
<item>60</item>
<item>300</item>
<item>900</item>
</string-array>
and the snippet from res/xml/preferences.xml:
<ListPreference
android:key="alarm_delay_list"
android:title="Alarm Delay"
android:summary="Click to change the alarm delay"
android:entries="@array/alarm_delay_keys"
android:entryValues="@array/alarm_delay_values"
android:dialogTitle="Choose your alarm delay\n(default
is 1
minute)"
android:defaultValue="60"
/>
If I change the value in the options menu, the radio gets set to the
correct value. The timer works, but keeps using the default value of
30 no matter what I set the value to in the options menu.
I assume this means I am not retreiving the preferences, since the
default value is set at:
seconds = Integer.parseInt(settings.getString("alarm_delay_keys",
"30"));
As you can see above, I tried several variations for calling
PreferenceManager, but these did not make a difference.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---