使用键值对进行本地存储(分类存储、获取)
来源:互联网 发布:数据脱敏 英文 编辑:程序博客网 时间:2024/05/18 03:27
做法:
activity_two.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/ed_name1" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入账号" /> <EditText android:id="@+id/ed_pass1" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="请输入密码" /> <CheckBox android:id="@+id/ed_cba" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="记住账号和密码"/> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:onClick="login1" android:text="登陆"/></LinearLayout>ThreeActivity
package com.liyulei.memoryread;import android.content.SharedPreferences;import android.os.Bundle;import android.support.v7.app.AppCompatActivity;import android.view.View;import android.widget.CheckBox;import android.widget.EditText;import android.widget.Toast;public class ThreeActivity extends AppCompatActivity { EditText ed_name1,ed_pass1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_two); } //外存卡存储信息 public void login1(View view ) { //拿到输入框的内容 EditText ed_name1 = (EditText) findViewById(R.id.ed_name1); EditText ed_pass1 = (EditText) findViewById(R.id.ed_pass1); String name1 = ed_name1.getText().toString(); String pass1 = ed_pass1.getText().toString(); //判断checkbox是否选中 CheckBox ed_cba = (CheckBox) findViewById(R.id.ed_cba); if (ed_cba.isChecked()) { //获取一个sharepreserce SharedPreferences sp = getSharedPreferences("info",MODE_PRIVATE); //获取编辑器 SharedPreferences.Editor ed = sp.edit(); ed.putString("name1",name1); ed.putString("pass1",pass1); //提交 ed.commit(); } Toast toast = Toast.makeText(this, "登陆成功", Toast.LENGTH_LONG); toast.show(); } //外存卡读取信息 public void Account() { //获取sharePrefence SharedPreferences sharedPreferences = getSharedPreferences("info",MODE_PRIVATE); String name = sharedPreferences.getString("name1"," "); String pass = sharedPreferences.getString("pass1"," "); ed_name1.setText(name); ed_pass1.setText(pass); }}
0 0
- 使用键值对进行本地存储(分类存储、获取)
- 使用phonegap进行本地存储
- 数据存储(1)--键值对
- JS端的localStorage:HTML5提供的本地存储(可以称为“键值对”数据库)
- 使用存储过程获取数据并对数据进行解析
- 实现键值对存储(一):什么是键值对存储,为什么要实现它
- 实现键值对存储(二)——以现有键值对存储为模型
- TStringList中的键值对存储
- Android SharedPreference存储键值对
- 使用localStorage进行本地存储代码
- [转]实现键值对存储(长文)
- 键值存储
- Android 对用户名密码进行加密操作存储在本地
- 使用文件对数据进行存储、访问
- HTML5 - Web存储使用详解(本地存储、会话存储)
- SortedList: 存储键值对的集合
- 实现一个键值对存储:目录
- Properties是Hashtable的一个子类:以文件来进行存储键值对
- cloudera manager 设置开机自启
- 块元素的作用
- javaScript面向对象编程
- Sublime Text3
- springMVC框架--json数据的交互(四)
- 使用键值对进行本地存储(分类存储、获取)
- 24点表达式去重--c++实现
- av_dump_format函数
- Access restriction: The type * is not accessible due to restrict,报错问题
- 练习题2016.11.8
- ansoft maxwell报错ansoft maxwell报错, 激励与激励相互重叠(excitation and excitation overlap
- 加密安装Kli Linux
- 大数据面试题解决方案
- C++继承总结