java - 更新 MoneyTextView Android Studio

标签 java android android-studio currency

我正在 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 的代码。我的代码出现错误无法解析方法“setText(java.lang.String)”。我认为这是因为 setText 只能与 TextView 一起使用,但是 MoneyTextView 的替代品是什么?

最佳答案

你必须使用moneyTextView.setAmount(value);

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

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

与:

mTotalPrice.setAmount(mTotal);

检查自述文件的链接: https://github.com/fabiomsr/MoneyTextView

关于java - 更新 MoneyTextView Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51544517/

相关文章:

java - JFrame 中的 DefaultTableModel 仅在行上创建 - JAVA

java - 如何在java中动态传递方法名

java - 使布局适应 hdpi 和 xhdpi

android - 如何在android中隐藏网页的地址栏?

来自 Eclipse 的 Android Studio

android-studio - Facebook 登录 AsyncTask #4 NullPointerException 启动时崩溃

jar - Java编译器多平台

java - 如何创建表示对象的 XML 属性

android - 动态创建的 Firebase 动态链接在 Android 上不起作用

android - 网格布局列跨度不起作用