微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何保存 ConcatAdapter()?科特林

如何解决如何保存 ConcatAdapter()?科特林

如何保存这种数据类型“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 举报,一经查实,本站将立刻删除。