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" />
11
  • I think you should use this to get the number of lines in your textview textView.getLineCount()
    – L2_Paver
    Commented Oct 8, 2019 at 0:33
  • can you please write full code. should i use if else staement?
    – Coder
    Commented Oct 8, 2019 at 0:42
  • replace myHolder.userTexts.getMaxLines()==4 with this myHolder.userTexts.getLineCount()>=4
    – L2_Paver
    Commented Oct 8, 2019 at 0:46
  • i tired but does not work
    – Coder
    Commented Oct 8, 2019 at 0:53
  • where did you put your if statement? your logic is correct try debugging your code and check your program flow
    – L2_Paver
    Commented Oct 8, 2019 at 0:59

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.