2015-10-08 92 views
0

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

+2

在'onCreate'参考初始化后把'yourTextView.setText(String.valueOf(2));' – Rustam

+0

设置为静态值,如2 – Androider

+0

你添加到你的文章中的那段代码没用。 – jhamon

回答

2

你既可以在活动的onCreate方法调用display(2);或编辑XML布局,使您的quantitiy的TextView的值是默认值为2。