I need to show some view when my mTxtText
has maxLinesCount
or more lines.
I checked these questions: first and second
What I have as a result in my getView
method:
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);
}
}
});
But I have got very interesting results: this listener is called only for some items in my adapter and for other items the visibility of mTxtExpand
is set randomly. When I scroll my list even items for which the listener was called show wrong views.
Thanks for any help.