在Activity中使用SharedPreferences sp=this.getSharedPreferences("zhy", this.MODE_WORLD_WRITEABLE);其中zhy是文件的名字,不包含擴張名。就可以獲得一個SharedPreferences的對象,使用SharedPreferences的對象就可以從xml中獲得數據。
寫數據時,
Editor editor=sp.edit();
editor.putInt("hight",value);
editor.commit();
不要忘記editor.commit()。
作者 張譯成