因此,这是刷新功能的相关部分,是导致问题的部分:
private fun refresh(root: View, refreshThing2: SwipeRefreshLayout, adapter: AwaitingAdapter) {
val sharedPreferences = root.context.getSharedPreferences(PREF_NAME, PRIVATE_MODE)
lifecycleScope.launch {
when (val arrayThing =
sharedPreferences.getString("userToken", "tttt")
?.let { CMSAPI().getAwaiting(it) }) {
is Result.Success -> {
adapter.clear()
adapter.addAll(arrayThing.value)
adapter.printList()
val textThingTest = root.findViewById<TextView>(R.id.text_no_awaiting)
textThingTest.visibility = View.GONE
refreshThing2.isRefreshing = false
第三方的两个主要功能是:adapter.clear()
和adapter.addAll()
。这就是这两个功能的内容。
fun clear() {
list.clear()
notifyDataSetChanged()
}
fun addAll(items: List<AwaitingItem>) {
list.addAll(items)
notifyDataSetChanged()
}
list
变量只是适配器的数据集。在调用这两个函数之后,我调用了一个打印出list
变量的函数。这是输出,其中删除了某些详细信息:
[AwaitingItem(title=null, image=null, content=test, id=anid, date=null, description=null, approvedBy=0, disapprovedBy=0, shouldNotify=false, shouldTweet=false, writerUsernameOnCreation=Jason, writerUserId=anid, isNews=false, type=null), AwaitingItem(title=bruh, image=https://.com/--4d95-93d528d6d701479b/, content=teeest, id=cb079yrcsZEm1z0V, date=October 24, 2020, description=f, approvedBy=0, disapprovedBy=1, shouldNotify=false, shouldTweet=false, writerUsernameOnCreation=f, writerUserId=idan, isNews=true, type=NEWS)]
它的外观应该是第二个位置的文章,顶部是一个提要项。但是,当我使用“布局检查器”时,它显示实际上有2则新闻文章,而在最上面的文章中有供稿项。
是什么原因导致此问题?