Question

I am still new to android and i am trying to make a notes application

i want the user to be able to type anything in the title (text) but only display a few characters (say 15) followed by (...)

i tried searching for this but the only thing i found is how to LIMIT size of text ( i do not want to do that i just want to limit what is viewed)

i do not want to do the following:

android:maxLength="10"

so my question is : what is the best way to do that? also is there a way to do it in xml or only in java?

Any help is appreciated :)

Was it helpful?

Solution

Write this inside your textView

    android:ellipsize="end"
    android:maxLines="1"
    android:singleLine="true"

and if you want to scroll in textView use this

    android:scrollHorizontally="true"

http://developer.android.com/reference/android/widget/TextView.html#attr_android:ellipsize

OTHER TIPS

Its not an answer , more of a comment , but you can try android:singleLine = "true".

source

You just change

android:layout_width="wrap_content"

use this below line

android:layout_width="match_parent"

<LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_toRightOf="@+id/visitBox"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/txvrequestTitle"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="Abcdefghighiklmnon"
                android:textAppearance="?android:attr/textAppearanceLarge"
                android:textColor="@color/orange_color" />


        </LinearLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top