部分代码 public static class school_teacherNameReadWrite{
public static SharedPreferences Read(Context context ){
SharedPreferences preferences=null;
preferences=context.getSharedPreferences("school_teacherName",Context.MODE_PRIVATE);
return preferences;
}
public static void Write(Context context,String schoolname){
SharedPreferences preferences=null;
preferences=context.getSharedPreferences("school_teacherName",Context.MODE_PRIVATE);
Editor editor= preferences.edit();
editor.putString("schoolname",schoolname);
editor.commit();
}
}
包: Commom
public class DataStruct {
public static class login_info{
public String statuscode;
public String schoolname;
public String randomkey;
public String jsonparser;
public String firstClass;
public String secondClass;
public String thirdClass;
public String firstClassId;
public String secondClassId;
public String thirdClassId;
public login_info(){
this.schoolname="";
this.statuscode="";
this.jsonparser="";
this.randomkey="";
this.firstClass="";
this.secondClass="";
this.thirdClass="";
this.firstClassId="";
this.secondClassId="";
this.thirdClassId="";
}
}
}
我想把DataStruct里的数据通过一个整体在sharepreference进行保存和读取,这样在主程序里就可以通过全局变量调用想用的数据.要该怎么实现,
Common.Utility.school_teacherNameReadWrite.Write(loginActivity.this,result.schoolname);result是string 类型
preferences=Common.Utility.school_teacherNameReadWrite.Read(MainActivity.this);
SchoolName.setText(preferences.getString("schoolname",""));
这是主程序里的写和读,没有错,如果实现了上面的该怎么改