【问题标题】:Text not appearing in some TextViews in RecyclerView, eventhough setText is called in Android 4.4即使在 Android 4.4 中调用了 setText,RecyclerView 中的某些 TextView 中也没有出现文本
【发布时间】:2019-04-29 11:44:08
【问题描述】:

我有一个 RecyclerView,每一行都是一个带有多个 TextView 的 LinearLayout。在较新的 android 版本上一切正常,但是当需要滚动并且应用程序在 Android 4.4 上运行时,一些 textViews 是空的,即使它们的值已分配并调用了 onBindViewHolder。

我尝试过使 TextView 无效并检查 textview 的其他属性是否有效,它们是否有效,唯一的问题是文本。 看起来是这样的:

我的 LinearLayout 组件:

init {
        isFocusable = true
        isClickable = true
        isFocusableInTouchMode = true
        background = ContextCompat.getDrawable(context, R.drawable.row_background)
        textViews.forEach {
            addView(it)
            it.maxLines = 1
            it.gravity = Gravity.CENTER
        }
}

这就是它现在在 Kit Kat 上的样子:


应该是这样的:

【问题讨论】:

    标签: android android-recyclerview textview android-4.4-kitkat


    【解决方案1】:

    在 onBindViewHolder 中添加绑定.executePendingBindings()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多