Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

textView.getLineCount() is not working as expected

There is a TextView inside ListView.
I set maxLine of TextView through codding like bellow.

view.textView.setText("....... Long String.........");
    view.textView.post(new Runnable() {
       @Override
       public void run() {

        if(view.textView.getLineCount > 4) {
           view.tv_read_more.setVisibility(View.VISIBLE);
           view.textView.setMaxLines(4);
        }
       }
    });

Problem : textView.setMaxLine() not working first time.
textView affected after ListView scroll down and scroll up

like image 410
Chirag Savsani Avatar asked Mar 04 '26 00:03

Chirag Savsani


1 Answers

I have an example in RecyclerView,this is work well.

 mDes.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                @Override
                public boolean onPreDraw() {
                    mDes.getViewTreeObserver().removeOnPreDrawListener(this);
                    int lineCount = mDes.getLineCount();
                    Log.e("TreeObserver", "onBind: " + lineCount1);
                    if (lineCount1 < 4 || isExpand) {
                        mArrowContainer.setVisibility(View.GONE);
                    } else {
                        mArrowContainer.setVisibility(View.VISIBLE);
                    }
                    return true;
                }
            });
like image 109
joe Avatar answered Mar 06 '26 01:03

joe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!