qq_22555381 2015-01-30 03:36 采纳率: 0%
浏览 1500

shareprefeneh和数据结构

部分代码 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",""));
                            这是主程序里的写和读,没有错,如果实现了上面的该怎么改
  • 写回答

1条回答 默认 最新

  • bdmh 移动开发领域优质创作者 2015-01-30 03:40
    关注
    评论

报告相同问题?

悬赏问题

  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示