Add multiple lines to TextView
I have some lines in xml like
<string name="String1">My String 1</string> <string name="String2">My string 2</string> and I want to show in action something like My String 1: My string 2
Is it possible to add to the same TextView more than
<TextView android:text="@string/String1"/> <TextView android:text=": "/> <TextView android:text="@string/String2"/> The problem is that if you insert them inside a TableLayout, they are considered cells, and the ":" character is not written next to String1 (it is written in the middle of both rows).
Is it possible to bind a string with only one TextView in xml code (without Java programming)? I mean, is there any syntax for adding lines like
<TextView android:text="@string/String1+: +@string /String2"/> thanks
You cannot do it directly in xml, this is the best you can do:
<string name="welcome_messages">Hello, %1$s! You have %2$d new messages.</string> Resources res = getResources(); String text = String.format(res.getString(R.string.welcome_messages), username, mailCount); I am not 100%, but I do not think that it is possible to have more than one android: text in TextView.
If you have three TextViews, you need to add something like String2 (or any kind has " : ":
android:layout_toRightOf="@id/string1" See this related question I asked earlier.
It is not possible to do anything interesting for strings in XML. You need to do this in Java.
Take a look at the API for TableRow :
android:layout_span - Determines how many columns this child should have.
So, I think you could use smth like:
<TableRow android:layout_span="3"> <TextView android:id="@+id/your_entire_string" /> </TableRow> Then in the Activity find the TextView by id and fill in ("My String 1" + ":" + "My String 2").