亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 customtextview 中連接可變文本值和固定字符串

如何在 customtextview 中連接可變文本值和固定字符串

開滿天機 2023-02-23 16:38:18
我可以在堆棧溢出的幫助下設法生成自定義 TextView,現在我很想將可變文本與固定字符串連接起來。我已經這樣做了,但沒有幫助。import android.content.Context;導入 android.support.annotation.Nullable;導入 android.util.AttributeSet;公共類 CustomTextViewTest 擴展 android.support.v7.widget.AppCompatTextView {public CustomTextViewTest(Context context) {    super(context);}public CustomTextViewTest(Context context, @Nullable AttributeSet attrs) {    super(context, attrs);}public CustomTextViewTest(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {    super(context, attrs, defStyleAttr);}@Overridepublic void setText(CharSequence text, BufferType type) {    super.setText(text, type);    // here set color according to text    if (text.toString().contains("Available")) {        this.setTextColor(getResources().getColor(R.color.green));    }    if(text.toString().contains("Not Available")){        this.setTextColor(getResources().getColor(R.color.red)); }    if(text.toString().startsWith("0")||text.toString().startsWith("1")||text.toString().startsWith("2")||text.toString().startsWith("3")||text.toString().startsWith("4")||text.toString().startsWith("5")||            text.toString().startsWith("6")||text.toString().startsWith("7")||text.toString().startsWith("8")            ||text.toString().startsWith("9")){        setText(text.toString()+" $");  //this line show something unexpected    }}}如何擺脫這個?
查看完整描述

1 回答

?
吃雞游戲

TA貢獻1829條經驗 獲得超7個贊

如果要顯示數值并在末尾添加美元符號,首先定義一個格式字符串資源,如下所示:


<string name="amount">%1$s $</string>

然后提供如下數值:


double amount = "100.00"

...

amountTextView.setText(context.getString(R.string.amount, amount));


查看完整回答
反對 回復 2023-02-23
  • 1 回答
  • 0 關注
  • 79 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號