0

Check if textview is ellipsized in android I try to use this but doesnt work. Some guy said add Runnable to this but it seems still doesnt work. Any help?

This is my code.

fun isShownLoadMoreButton(
tvDescription: TextView,
btnReadMore: TextView,
description: String
) {
if (description.isEmpty()) {
    btnReadMore.visibility = View.GONE
} else {
    tvDescription.apply {
        ellipsize = TextUtils.TruncateAt.END
        maxLines = MAX_LINE_DESCRIPTION
        if (layout != null) {
            val lines: Int = layout.lineCount
            if (lines > 0) {
                val ellipsisCount: Int = layout.getEllipsisCount(lines - 1)
                if (ellipsisCount > 0) {
                    btnReadMore.visibility = View.VISIBLE
                } else {
                    btnReadMore.visibility = View.GONE
                }
            }
        }

    }
}

}

  • Is it ellipsized by default when initial the view ? – Mustafa Ibrahim Feb 25 '21 at 11:13
  • I suggest you try to describe your problem in more detail. The title of your post suggests that it has something to do with the view pager. Is it tab text or just the text view in the viewpager's fragment? – kolboc Feb 25 '21 at 12:26
  • My viewpager is recyclerview. And that textview is on viewholder. I use databinding to bind text to tvDescription. So I guess not enough time to render tvDescription -> layout = null. – mlh_trungnh1 Feb 26 '21 at 02:18

0 Answers0