问题描述
如何保存这种数据类型“Concat Adapter()”?我用 json 尝试过 sharedPreferences 但它没有用。
我想保存一个带有不同 ViewHolders 的 RecyclerView 以在重新打开应用程序后显示,但我找不到方法。
class MainActivity : AppCompatActivity(){
var userList: MutableList<ExampleItem> = mutablelistof()
var userList2: MutableList<ExampleItem> = mutablelistof()
var adapterLst : ConcatAdapter = ConcatAdapter()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
recycler_view.layoutManager=GridLayoutManager(this,2)
recycler_view.setHasFixedSize(true)
userList2.add(ExampleItem("cuatro","cinco"))
userList.add(ExampleItem("cuatro","cuatro"))
adapterLst = ConcatAdapter(ExampleAdapter(this,userList),typ2Adapter(this,userList2))
recycler_view.adapter = adapterLst
save.setonClickListener {
saveData()
}
}
private fun saveData() {
val sharedPreferences = getSharedPreferences("shared preferences",Context.MODE_PRIVATE)
val editor = sharedPreferences.edit()
val gson = Gson()
val json = gson.toJson(adapterLst)
editor.putString("recycler list",json)
editor.apply()
}}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)