简体   繁体   中英

I am building an application using Android Studio

I am using Android Studio.I want to use "View More" after some letters in a textview. I have searched for it and it shows how to add "View More" after a specific number of lines but I want to add it after a specific number of letters. Can anybody suggest what should I do?

As far as I understand your problem

Suppose you have a String

String name="Rajdev Stack overflow"

name has 21 characters/letters(including spaces).

If you want to show only upto 10 charchters and then view more, you can trim this String upto first 10 characters.

String trimmedName = name.substring(0, Math.min(name.length(), 10));

Now trimmedName contains only upto 10 characters. Now you can do:

trimmedName+"... view more";

so the user will see 10 characters and then view more

Rajdev Sta... view more

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM