elajaj bilal Posted May 17, 2012 Share Posted May 17, 2012 salut tout le monde mon but est de stocker les données détectent par le GPS intégrer dans smartphone ; Il existe plusieurs manières de procéder ,mais j'ai choisi les préférences partagées . voici mon code (juste pour enregistre quelques valeurs ): package PFE.Lirefichier; import android.app.Activity; import android.content.SharedPreferences; import android.os.Bundle; import android.widget.Toast; public class main extends Activity { public static final String PREFS_NAME="MayPresFile"; public static final String text1=" bonjour tout le monde "; public static final String text2=" bonjour "; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); SharedPreferences myPrefs = this.getSharedPreferences(PREFS_NAME, MODE_WORLD_READABLE | MODE_APPEND); SharedPreferences.Editor prefsEditor = myPrefs.edit(); prefsEditor.putLong("2",26); prefsEditor.putLong("3",27); prefsEditor.putLong("4",28); prefsEditor.commit(); for(int i=1;i<=4;i++){ SharedPreferences myPrefs1 = this.getSharedPreferences("MayPresFile", MODE_WORLD_READABLE); Long prefName = myPrefs1.getLong("i", 0); Toast.makeText(this, " la valeur est :" +prefName + "\n" , Toast.LENGTH_LONG).show(); } } } mais il m'affiche la dernière valeur ( 28), merci d'avance Link to comment Share on other sites More sharing options...
arnouf Posted June 6, 2012 Share Posted June 6, 2012 et si tu remplaçais myPrefs1.getLong("i", 0); par myPrefs1.getLong(""+i, 0); ?? Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.