当前位置:网站首页>checkbox的使用
checkbox的使用
2022-04-22 10:06:00 【我还能码嘛。】
情景
在用户第一次登录时,根据他的选择是否将密码保存在本地,并在下次打开应用时自动填充

解决方法
使用SharedPreferences本地储存
//判断是否为第一次登录
val prefs = getSharedPreferences("data",Context.MODE_PRIVATE)
val prefsEdit = getSharedPreferences("data",Context.MODE_PRIVATE).edit()
val isRemember = prefs.getBoolean("remember_password",false)
//读取之前的密码
if (isRemember){
Log.d("Login.out","isRemember = $isRemember")
val username = prefs.getString("account","")
val password = prefs.getString("password","")
loginBinding.usernameEdit.setText(username)
loginBinding.passwordEdit.setText(password)
loginBinding.rememberPass.isChecked = true
}
使用checkbox

要设置checkbox的点击监听事件!!
然后再判断他是否被选上
loginBinding.rememberPass.setOnClickListener {
//用户选择记住密码 将用户名和密码保存在本地
if (loginBinding.rememberPass.isChecked){
Log.d("Login.out","isRememberPass = $isRemember")
prefsEdit.putBoolean("remember_password",true)
prefsEdit.putString("account",loginBinding.usernameEdit.text.toString())
prefsEdit.putString("password",loginBinding.passwordEdit.text.toString())
prefsEdit.apply() //这一句别忘了
}
}
版权声明
本文为[我还能码嘛。]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_50754064/article/details/124283037
边栏推荐
- source_ Insight is a method to create a new project and search for a variable or function in the whole document
- linux7静默安装oracle12c报错[FATAL] [INS-35344]The value is not specified
- DA14580BLE点亮LED
- Cloud native enthusiast weekly: looking for open source alternatives to netlify
- [go] program flow control
- Beyond iterm! Known as the next generation terminal artifact, powerful!
- IOS development - Database - Introduction to basic knowledge (01)
- cobbler补鞋匠
- JWT源码浅析(四层封装,有示意图)
- Intermediary model
猜你喜欢

Nacos

dataguard (ADG)备库移动(迁移)数据文件

【C语言进阶10——字符和字符串函数及其模拟实现(1)】

内存管理-

Beyond iterm! Known as the next generation terminal artifact, I can't put it down after using it!

Zhongshanghui ⺠ evolution of trading platform architecture: response to Apache shardingsphere

Beyond iterm! Known as the next generation terminal artifact, powerful!

二极管工作原理

三极管、场效应管和MOS管三者的工作原理

Cloud native enthusiast weekly: looking for open source alternatives to netlify
随机推荐
leetcode771. 宝石与石头
跨平台编译
[flutter topic] 125 illustrated autobiography ace_ ICON. Ttf Icon Library
[QT notes] use qpainter to draw various basic graphics
柯里化的两种写法(弄懂`fn.length`与`fn.toString()`)
Transform based deep learning target detection (Detr model)
项目实训-读报僵尸
Matplotlib tutorial 04 --- drawing commonly used graphics
Text justify, orientation, combine text attributes
UVC camera 封装类
linux7静默安装oracle12c报错[FATAL] [INS-35344]The value is not specified
[age appropriate friends of interesting programming questions] (detailed explanation of the original title of leetcode)
Nacos
[go] program flow control
matplotlib教程04---绘制常用的图形
L2-033 simple calculator (25 points)
LC301. 删除无效的括号
The working principle of triode, FET and MOS transistor
You need to specify one of MySQL_ ROOT_ PASSWORD, MYSQL_ ALLOW_ EMPTY_ PASSWORD and MYSQ
Linux 7 silent installation of Oracle 11g