【问题标题】:Android kotlin use Multiple thread (coroutine) to load videos from server to recycler viewAndroid kotlin 使用多线程(协程)将视频从服务器加载到回收站视图
【发布时间】:2022-01-03 21:57:14
【问题描述】:
    var list:ArrayList<ProfilePost> = ArrayList()
    GlobalScope.launch {
        list=  apiInterface.GetVideosByUser(ApiInterface.PublicationRequestBodyGet(id.toString()))
            .await().publications
    }

    runOnMainThread {
        adapter = ProfilePostAdapter(list, "mine")
        recylcerPost.adapter = adapter
        recylcerPost.layoutManager = GridLayoutManager(context, 3)
    }

在这段代码中,我无法获取列表变量中出版物的值,因此列表保持为空。 而且我需要将回收站视图的创建与 GetVideosByUser 函数分开,因为它会冻结我的屏幕

【问题讨论】:

    标签: android kotlin retrofit


    【解决方案1】:

    您需要使用空列表创建 RecyclerView,然后在您从协程中获得列表时更新它。更多信息在这里:How to update RecyclerView Adapter Data

    【讨论】:

      猜你喜欢
      • 2023-01-10
      • 1970-01-01
      • 2020-05-29
      • 2016-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多