1
I have a simple settings menu where I have a CheckBoxPreference
. I want to set silent mode when the checkbox is checked and normal mode when it is not checked. The sound code I already have, but I’m having trouble getting the value of checkBoxPreference,since I only have the settings class that extends PreferenceActivity
. Follow the code below:
Prefs.java
package br.com.pedro.menu;
import br.com.pedro.school.R;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class Prefs extends PreferenceActivity {
AudioManager som;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.prefs);
// USE AudioManager for Settingringing from vibration
som = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
}
}
xml/prefs.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory android:title="@string/geral" >
<CheckBoxPreference
android:key="silenciar"
android:summary="@string/mudo_inst"
android:title="@string/mudo" />
</PreferenceCategory>
please help me!
How could I Test the checkbox and save it at the same time?
– Pedro Igor
What do you mean, save him?
– ramaral
Use of class
SharedPreferences
for when the user terminates the application and returns, Checkboxpreference is marked in the way that it set previously!– Pedro Igor