Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display multiline from array list in single TextView?

I am developing android apps so in that i want display the four lines of text in single text view. my Array list contain data like following

Customer Name : Nilesh
Customer Contact : 23230200
Customer City : Pune

but when I write code like following only last line was displayed from the array List

XML

  <TextView android:id="@+id/kbpViewTvCustNm"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="8dp"
            android:lines="4"
            android:textIsSelectable="false" />

code

for (String details : list2)
  {
     custName.setText(details);
  }
like image 328
nilesh wani Avatar asked Jun 26 '13 06:06

nilesh wani


2 Answers

Use a StringBuilder to make your array 1 String and append linebreaks in between the individual Strings like this:

StringBuilder builder = new StringBuilder();
for (String details : list2) {
   builder.append(details + "\n");
}

custName.setText(builder.toString());
like image 69
Ostkontentitan Avatar answered Sep 19 '22 16:09

Ostkontentitan


<TextView
            android:id="@+id/kbpViewTvCustNm"
            android:layout_width="100dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="8dp"
            android:lines="4"
            android:textIsSelectable="false" />
like image 42
Samadhan Medge Avatar answered Sep 22 '22 16:09

Samadhan Medge