java - 初始化数量

标签 java android

我希望当我的应用程序启动时,它显示 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);
}

enter image description here

最佳答案

您可以在 Activity 的 onCreate 方法中调用 display(2); 或编辑 xml 布局,使数量 TextView 的值默认为 2。

关于java - 初始化数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33015290/

相关文章:

java - 是否可以自定义 Spring Cache 抽象使用的序列化?

java - 一个 JDBC 连接中可以有两个并发事务吗?

java - JDK10支持AOT编译吗?

java - 如何创建我自己的 jOOQ 结果?

android - CPU加速状态: KVM is not installed on this machine (/dev/kvm is missing)

android - RxJava返回错误为onNext并继续流

java - 代码中的枚举错误

android - 如何将选定的自定义数组列表值放置到相同的自定义数组列表中,但最多只能放置 5 个中的 3 个

android - android studio 中的 Kotlin Gradle 插件问题

java - ClassName.this 消除歧义的目的是什么?