Android之SharedPreferences用法
来源:互联网 发布:双语字幕制作软件 编辑:程序博客网 时间:2024/06/11 01:14
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(); } } }); } }
0 0
- Android之SharedPreferences用法
- Android之SharedPreferences 的用法
- Android之SharedPreferences的基本用法
- Android进阶之SharedPreferences的基本用法
- Android SharedPreferences用法
- android SharedPreferences简单用法
- Android学习:SharedPreferences用法
- Android-SharedPreferences用法
- android Sharedpreferences 用法实例
- android sharedPreferences的用法
- android SharedPreferences的用法
- Android SharedPreferences用法
- android SharedPreferences用法
- Android中SharedPreferences用法
- Android中SharedPreferences用法
- Android - SharedPreferences的用法
- Android中SharedPreferences用法
- Android Sharedpreferences用法
- NLP大神推荐的机器学习入门书单(附大量百度网盘电子书)
- 单元测试辅助工具Hamcrest详解
- linux学习笔记--pmap命令
- Android.mk理解
- springMVC源码分析--RequestMappingHandlerAdapter(五)
- Android之SharedPreferences用法
- socket通信之心跳
- 最大流算法
- 快速生成react项目
- JS(四)RegExp正则表达式
- JVM调优总结 -Xms -Xmx -Xmn -Xss
- PCL在VS2013下快速安装或者cmake详细安装(可以运行kinectFusion使用kinect1拍摄深度图彩色图三维模型)两种安装方式
- Scrapy爬虫(六):多个爬虫组合实例
- flask相关资料