mTxtText
当我有maxLinesCount
或更多行时,我需要显示一些视图。我检查了这些问题:第一个和第二个
我的getView
方法得到的结果是:
mTxtText.setText(Html.fromHtml(output));
mTxtText.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener() {
@SuppressWarnings("deprecation")
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mTxtText.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
} else {
mTxtText.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
}
if (isCollapseOn
&& mTxtText.getLineCount() >= maxLinesCount) {
mTxtExpand.setVisibility(View.VISIBLE);
} else {
mTxtExpand.setVisibility(View.GONE);
}
}
});
但是我得到了非常有趣的结果:这个监听器只被我适配器中的一些项目调用,而其他项目的可见性mTxtExpand
是随机设置的。当我滚动列表时,甚至调用侦听器的项目也会显示错误的视图。
谢谢你的帮助。