ZAJ
ZAJ

Reputation: 835

TextView does not show all the text

I have a Ui which shows customer information. The problem I have is some customer name(android:id="@+id/customerName") is long and does not fit in the textview. what option i ahev to beable to display them other then the option to give full layout width to the name or removing the code textview from next to it(as seen in the xml file android:id="@+id/customerName").

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:stretchColumns="*" >

    <TableRow>

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/customerCode" />

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/customerName" />
    </TableRow>

    <TableRow>

        <TextView
            android:id="@+id/customerCode"
            style="@style/CustomerTextView"
            android:gravity="right" />

        <TextView
            android:id="@+id/customerName"
            style="@style/CustomerTextView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:gravity="right"
            android:maxEms="5"  />
    </TableRow>

    <TableRow android:gravity="right" >

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/customerAddress" />
    </TableRow>

    <TableRow android:gravity="right" >

        <TextView
            android:id="@+id/customerAddress"
            style="@style/CustomerTextView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:gravity="right"
            android:maxEms="5"   
            />
    </TableRow>

    <TableRow>

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/POBox" />

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/OrganizationName" />
    </TableRow>

    <TableRow>

        <TextView
            android:id="@+id/poBox"
            style="@style/CustomerTextView"
            android:gravity="right" />

        <TextView
            android:id="@+id/organizationName"
            style="@style/CustomerTextView"
            android:gravity="right" />
    </TableRow>

    <TableRow>

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/fax" />

        <TextView
            style="@style/CustomerLabelTextView"
            android:gravity="right"
            android:text="@string/phone" />
    </TableRow>

====================================STYLE++++++++++++++++++++++++++++++++++++++++

<style name="CustomerTextView">
  <item name="android:layout_width">fill_parent</item>
  <item name="android:layout_height">wrap_content</item>
  <item name="android:textSize">14sp</item>
  <item name="android:textColor">@android:color/white</item>
  <item name="android:layout_margin">5dp</item>
  <item name="android:background">@drawable/textview_border</item> 

Upvotes: 1

Views: 18399

Answers (5)

touchchandra
touchchandra

Reputation: 1556

I fixed it by using

android:layout_height="wrap_content"
android:inputType="textMultiLine"

hope this works for you too.

Upvotes: 9

mungaih pk
mungaih pk

Reputation: 1911

You can try and make the textview scrollable so that when the data to display is too much,scrolling will reveal the hidden text. In the xml file,change LinearLayout to ScrollView layout.

Upvotes: 0

Eren Tantekin
Eren Tantekin

Reputation: 1461

You can make the TextView expand to a second line by setting singleLine attribute to false.

<TextView
        android:singleLine="false"
/>

Upvotes: 0

Geobio Boo
Geobio Boo

Reputation: 1354

One option is to make it ellipsize, so if a name is 'Really Long Name", it might show up as "Really Lon...". To do this:

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

On the other hand, you can make the textview change size to fit the text using:

android:layout_width="wrap_content"

But I'm not sure if it'll work with everything else you're trying to do (eg fill_parent and width inside a tablerow)

Upvotes: 2

G M Ramesh
G M Ramesh

Reputation: 3412

remove the android:maxEms="5" line in xml file and than try

Upvotes: 0

Related Questions