我正在 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/