package com.dingxiaomiao.sharedpreferencestest;    import android.app.Activity;    import android.content.SharedPreferences;    import android.content.SharedPreferences.Editor;    import android.os.Bundle;    import android.view.View;    import android.widget.EditText;    import android.widget.Toast;    public class MainActivity extends Activity {        static final String KEY = "MyValues";        private EditText editText;        SharedPreferences preferences;        Editor editor ;        @Override        protected void onCreate(Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            setContentView(R.layout.activity_main);            editText = (EditText) findViewById(R.id.editText);            preferences = getPreferences(Activity.MODE_PRIVATE);            editor = preferences.edit();            findViewById(R.id.readbtn).setOnClickListener(                    new View.OnClickListener() {                        @Override                        public void onClick(View v) {                            String value = preferences.getString(KEY, "没有数据");                            Toast.makeText(getApplicationContext(), value,                                    Toast.LENGTH_LONG).show();                        }                    });            findViewById(R.id.writebtn).setOnClickListener(                    new View.OnClickListener() {                        @Override                        public void onClick(View v) {                            editor.putString(KEY, editText.getText().toString());                            if (editor.commit()) {                                Toast.makeText(getApplicationContext(), "写入成功",                                        Toast.LENGTH_LONG).show();                            }                        }                    });        }    }

更多相关文章

  1. android videoview 没有画面的一个原因
  2. ADT下载地址(含各版本)(转)
  3. android 3G pppd 调试记录
  4. Android(安卓)UI布局中设置了fill_parenet仍然没有全屏的解决办
  5. Android(安卓)UI布局中设置了fill_parenet仍然没有全屏的解决办
  6. android 3G pppd 调试记录。
  7. 监听Android应用程序是否卸载成功
  8. android:maxHeight,android:maxWidth失效
  9. android:maxHeight,android:maxWidth失效

随机推荐

  1. 这些node开源工具你值得拥有(上)
  2. php.ini 配置文件的深入解析
  3. Oracle 9i产品文档
  4. 实现core文件自动生成配置文件的方法
  5. RHEL6.5下JDK1.8安装教程
  6. 临摹应该从哪里开始?绘画中的临摹技巧
  7. tensorflow-cpu/gpu速度 cpu(3分钟)vs gpu(4
  8. php中Workerman框架实例讲解
  9. PHP优化教程之解决嵌套问题
  10. php中unable to fork报错简单解决方法