【发布时间】:2020-05-16 00:42:27
【问题描述】:
所以我正在尝试将 Imageview 保存到 sharedpreference 中,因此当用户从应用程序中选择图像时,如果有意义,图像将被保存并设置为 imageview id!当用户退出我的应用并重新打开它时,图像将与他保存的相同?
我尝试了这段代码,但它给了我诸如for input string " "之类的错误
我的共享偏好
CompassBtn.setOnClickListener{
val prefCompass = getSharedPreferences("Drawable", Context.MODE_PRIVATE)
val editor = prefCompass.edit()
editor.putInt("ic_compass", ic_compass.setImageResource(R.drawable.ic_compass1).toString().toInt())
editor.commit()
}
**这是我尝试检索它的方式**
val prfCompass = getSharedPreferences("Drawable", Context.MODE_PRIVATE)
prfCompass.getInt("ic_compass", 0)
请提前帮助和感谢
【问题讨论】:
-
您正在尝试保存图像,因此这意味着图像是从互联网(URL)加载的。如果是这种情况,您应该使用 Glide 或 Picasso,它们是用于下载、加载和处理缓存的 android-third-party-libraries。此外,如果 Remote 中的图像发生变化,它也会处理。
-
我在可绘制文件@AmitGupta 中有图像
-
请检查我添加的答案。希望对您有所帮助。
标签: android android-studio kotlin android-drawable