我希望当我的应用程序启动时,它显示 2 作为初始数量。总是显示0。我该怎么办?
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
int quantity = 2;
displayPrice (quantity * 5);
}
/**
* This method is called when plus button is clicked.
*/
public void increment(View view) {
int quantity = 2;
quantity = quantity + 1;
display(quantity);
}
/**
* This method is called when minus button is clicked.
*/
public void decrement(View view) {
int quantity = 1;
display (quantity);
}
最佳答案
您可以在 Activity 的 onCreate
方法中调用 display(2);
或编辑 xml 布局,使数量 TextView 的值默认为 2。
关于java - 初始化数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33015290/