2016-05-19 44 views
0

我想讓應用程序顯示像「24女孩」這樣的字符串; 但是當我使用dataBinding,字符串中的空間不能顯示,字符串更改爲「24girls」。如何使用dataBinding編寫帶空格的字符串

這是我的代碼: enter image description here

+2

歡迎StackOverflow上。請看看[如何提出一個好問題](http://stackoverflow.com/help/how-to-ask)上的一些有用提示 - 詢問一個好問題可以提高獲得答案的機會。 但是,在發佈您的問題之前,您先搜索並做一些調查也同樣重要。 請避免粘貼代碼的截圖,而是放置實際的文本並使用'code-markup'。 – ishmaelMakitla

+0

感謝大家回答我的問題,謝謝〜 – Lewis

回答

5

在XML試試這個:

android:text="@{setScore.score + ' ' + @string/score_string}" 
2

只給空白+' '+在得分之間和得分串

11

我會建議你使用plurals爲這個。 在你strings.xml補充一點:

<plurals name="scores"> 
    <item quantity="one">%d Girl</item> 
    <item quantity="other">%d Girls</item> 
</plurals> 

,並在佈局文件

android:text="@{@plurals/scores(setScore.score, setScore.score)}" 

第一setScore.score用來決定哪個字符串應該從plurals使用。 而第二個setScore.score用於我們在plurals中提到的參數%d

1

創建一個字符串資源:

<string name="score_string">%1d girls</string> 

,然後用它是這樣的:

android:text="@{String.format(@string/score_string, setScore.score)}" 
相關問題