码迷,mamicode.com
首页 > 其他好文 > 详细

数据存储之——sharedprefrence

时间:2015-02-09 11:10:09      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:sharedprefrence

//sharedprefrences

           //name 直接写名字  mode 通常用mode_private       

        sp = getSharedPreferences("config", MODE_PRIVATE);

btn_ok.setOnClickListener(new OnClickListener() {

          

           @Override

           publicvoid onClick(View v) {

             

                  String user = et_user.getText().toString().trim();

                  String pwd = et_pwd.getText().toString().trim();

                  if(user.isEmpty()||pwd.isEmpty()){

                     Toast.makeText(getApplicationContext(),"不能为空", 200).show();

                     //获取编辑器

                           Editor edit = sp.edit();

                         //保存数据

                          edit.putString("name", user);

                          edit.putString("pwd", pwd);

                          //提交保存

                          edit.commit();   

                  }            

           }

       });


 btn_show.setOnClickListener(newOnClickListener() {

           

            @Override

            publicvoid onClick(View v) {

                //获取用户名

                StringuserName = sp.getString("name", null);

                //获取密码

                Stringpassword = sp.getString("password", null);

                //显示

                et_name.setText(userName);

                et_password.setText(password);         

            }

        });




数据存储之——sharedprefrence

标签:sharedprefrence

原文地址:http://9882931.blog.51cto.com/9872931/1612857

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!