Renjith Krishnan
Renjith Krishnan

Reputation: 2636

Showing Large String in TextView in android

I need to show a Large text view in android,if the string length is small i want to show the whole text if the String length is high I want to show the texts in first the letters of the String followed by dots and then followed by the last part of the String.

Like if the String is 'Google' i want to show "Google" If the String is 'Google Play Developer Console' I want to show the String something like "Google P...Console" how can I achieve this?

Upvotes: 2

Views: 1443

Answers (3)

keshav
keshav

Reputation: 3255

This will solve your problem

android:ellipsize="middle"

Upvotes: 2

Looking Forward
Looking Forward

Reputation: 3585

if(string.length() <= 5)
            {
                tvAdd.setText(yourstring);
            }

            else
            {
                tvAdd.setText(yourstring.substring(0, 5) + "..");
            }

Upvotes: 0

flx
flx

Reputation: 14226

Use ellipsize to abbreviate the text:

<TextView android:layout_width="50dp"
          android:layout_height="match_parent"
          android:singleLine="true"
          android:ellipsize="middle"/>

Upvotes: 2

Related Questions