bravoborja / ReadMoreTextView

A Custom TextView with trim text
Apache License 2.0
1.69k stars 229 forks source link

Dosent Work with delay in setting text #30

Open gagan1994 opened 6 years ago

gagan1994 commented 6 years ago

It doesn't work when we set text with delay. i.e after executing onCreate

arunjnair15 commented 6 years ago

I got the same issue.

gagan1994 commented 6 years ago

use public class ReadMoreLoad extends ReadMoreTextView { public ReadMoreLoad(Context context) { super(context); }

public ReadMoreLoad(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
}

public ReadMoreLoad(Context context, AttributeSet attrs) {
    super(context, attrs);
}

@Override
protected void onGlobalLayoutLineEndIndex() {
    getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            ViewTreeObserver obs = getViewTreeObserver();
            obs.removeOnPreDrawListener(this);
            refreshLineEndIndex();
            setText();
            return false;
        }
    });
}

}

this will work for setting text with delay