アクティビティでこのコードを使用しています
protected void onResume() {
super.onResume();
prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
System.out.println(connections);
String dir = prefs.getString("download_directory", "Download");
System.out.println(dir);
}
私の設定.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="Downloads">
<EditTextPreference
android:key="download_directory"
android:title="@string/download_destination"
android:summary="@string/download_description"
android:defaultValue="FacebookPhotos"
android:dialogTitle="@string/download_destination" />
<CheckBoxPreference android:key="subdir_album"
android:title="@string/download_album"
android:summary="@string/download_album_description" />
</PreferenceCategory>
<PreferenceCategory android:title="Gallery">
<EditTextPreference
android:key="connections"
android:title="Concurrent connections"
android:numeric="integer"
android:maxLength="2"
android:defaultValue="7"
android:dialogTitle="Concurrent connections" />
</PreferenceCategory>
</PreferenceScreen>
によって編集
public class Preferences extends PreferenceActivity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
問題は、「接続」の値を取得すると、正しい int が返されるのではなく、キー「download_directory」の getString が常にデフォルト値の「Download」を返すことです。