2015-10-08 128 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。