droid68 Posted April 13, 2011 Posted April 13, 2011 Bonjoir, Après avoir lu maintes postes, tutoriels, je ne comprends toujours pas comment appeler les préférences ! j'ai un fichier /res/prefs.xml <?xml version="1.0" encoding="utf-8"?> <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"> <PreferenceScreen android:title="Vos informations"> <PreferenceCategory android:title="Categorie 1"> <EditTextPreference android:title="nom" android:summary="EditText" android:key="GT" /> </PreferenceCategory> </PreferenceScreen> </PreferenceScreen> ensuite j'ai le fichier preference public class Main extends PreferenceActivity implements OnSharedPreferenceChangeListener { /** Called when the activity is first created. */ SharedPreferences pref; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.prefs); } @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Toast.makeText(this,key + ":" + sharedPreferences.getString(key, ""), Toast.LENGTH_SHORT).show(); } } je n'arrive toujours pas a appeler d'une autre classe, j'ai une erreur (Sorry, The application has stopped unexplectly) quand je clique sur le boutonimage Et le code pour appeler la classe preference Intent i = new Intent(this, preference.class); startActivity(i); Merci de votre aide
chpil Posted April 14, 2011 Posted April 14, 2011 Puisque ta classe implémentant la gestion des préférences s'appelle "Main", c'est celle-là qu'il faut que tu appelles, pas celles qui s'appelle "preference" Intent i = new Intent(this, Main.class); startActivity(i);
droid68 Posted April 14, 2011 Author Posted April 14, 2011 Merci pour ta réponse mais j'avais oublié de le déclarer dans AndroidManifest ....
Recommended Posts
Archived
This topic is now archived and is closed to further replies.