更新 MoneyTextView Android Studio

Update MoneyTextView Android Studio

我正在 Android Studio 中创建一个应用程序,它使用 TextMoneyView 来显示价格。价格可以在用户选择商品时更新。

XML

<org.fabiomsr.moneytextview.MoneyTextView
    android:id="@+id/totalPrice"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textAlignment="center"
    app:baseTextSize="50dp"
    app:decimalSeparator="."
    app:symbol="£"
    app:symbolGravity="start|bottom" />

Java

private int mTotal = 0;
private MoneyTextView mTotalPrice;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ...
    mTotalPrice = (MoneyTextView) findViewById(R.id.totalPrice);
}

    public void smallAdd(View view) {
    mTotal += 3;
    ...
    if (mTotalPrice != null)
    {
        mTotalPrice.setText(Integer.toString(mTotal));
    }
}

我不确定如何更新它,所以我复制了一些我以前用来更新 TextView 的代码。我的代码有错误 Cannot resolve method 'setText(java.lang.String)'。我认为这是因为 setText 只能与 TextView 一起使用,但 MoneyTextView 的替代方案是什么?

尝试 moneyTextView.setAmount(156); 其中 156 是您的值。

您必须使用 moneyTextView.setAmount(值);

所以在你的情况下你必须改变:

mTotalPrice.setText(Integer.toString(mTotal));

与:

mTotalPrice.setAmount(mTotal);

查看自述文件的 link: https://github.com/fabiomsr/MoneyTextView