1

I want to show read more or continue reading if text has more than 4 lines. how to do that, I tried some way it doesn't work;

 if (myHolder.userTexts.getMaxLines()==4){
        myHolder.showMore.setVisibility(View.VISIBLE);
    } else {
        myHolder.showMore.setVisibility(View.GONE);
    }

And if you want to look at my layout;

        <TextView
            android:id="@+id/showMore"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="5dp"
            android:layout_marginLeft="5dp"
            android:text="@string/conti_read"
            android:visibility="gone"
            android:textStyle="bold"
            android:gravity="center"
            android:textSize="14sp" />
MohanKumar
  • 960
  • 10
  • 26
Coder
  • 53
  • 1
  • 7

1 Answers1

0

you can use this code

if (text.length() > length) {
            String sub = text.substring(0, length);

            textView.setText(Html.fromHtml(sub + "<font color='#F39322'> " + seeMore + "</font>"));


            textView.setOnClickListener(view -> {

                if (textView.getText().equals(text)) {
                    textView.setText(Html.fromHtml(sub + "<font color='#F39322'> " + seeMore + "</font>"));
                } else {
                    textView.setText(text);

                }
            });

        } else {
            textView.setText(text);

        }

please vote me if this was useful for you

Genius8020
  • 135
  • 1
  • 4