I have a listview backed by an adapter. Each row has a number of views, two of which are textviews. Because I need to call view.getMeasuredWidth()
on the textviews, I call and assign data to the textviews from inside onGlobalLayout()
as
textview.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@SuppressLint("NewApi")
@Override
public void onGlobalLayout() {
int length = Utils.getTextLengthToFitTextview(textview, strValue);
textview.setText(strValue.substring(0, length));
if (length < strValue.length()) {
textview2.setText(strValue.substring(length));
} else {
textview2.setVisibility(View.GONE);
}
if (Utils.hasJellyBean()) {
textview.getViewTreeObserver().removeOnGlobalLayoutListener(this);
} else {
textview.getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
}
});
Now for some reason, the content of textview and textview1 do not always match the appropriate row. When I scroll, the contents jump rows. Does anyone know how I might fix this? I create my adapter by extending the BaseAdapter.
Also I am using holder pattern for my views.