簡體   English   中英

setText()來自xml的多個字符串

[英]setText() multiple strings from xml

也許是一個簡單的問題-我需要幫助來設置來自strings.xml的多個字符串。

 mytext.setText(resources.getString(R.string.history_text1+R.string.history_text2));

所以我的意思是我需要通過一個setText將2個不同的文本作為一個文本。

但是使用這種語法,我有一個錯誤: android.content.res.Resources $ NotFoundException:字符串資源ID#0xfe1e0079

嘗試這個:

 mytext.setText(resources.getString(R.string.history_text1) + resources.getString(R.string.history_text2))

價值:
R.string.history_text1R.string.history_text2
是引用資源中實際字符串的整數。
通過添加它們,您將獲得另一個不引用任何內容的整數,因此您得到:

Resources$NotFoundException

如果要串聯兩個字符串值:

String value = resources.getString(R.string.history_text1) + resources.getString(R.string.history_text2)
mytext.setText(value);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM