2017-02-10 17 views
-6

創建一個字符串更新的邏輯。我是指像如何時,他改變了

贏/敗局

當我贏了,我有錢,我的帳戶從5000變爲5200,但是當我贏了下次我再次得到5200.

我知道什麼是問題,但我不知道如何解決它。

這裏是我的改變文字代碼時,WIN發生

String text = spinnerData.getSelectedItem().toString(); //i get data from spinner 
int temp = Integer.parseInt(text); //then i parseit to Int 
int temp2 = (temp*2); //profit 100% so *2 
btnCashCurrency.setText((5000 + temp2) + " $"); //and here i change text 

但這項工作等。當在微調200是我的文字將更改爲5200,但是當我使微調100我的文字將更改爲5100.

如何解決它?

回答

4

您總是將您的利潤添加到硬編碼5000,而不是保存當前金額並將其添加到硬編碼5000。

試一下:

// Define this as global variable 
int cash = 5000 

// When win: 
String text = spinnerData.getSelectedItem().toString(); //i get data from spinner 
int temp = Integer.parseInt(text); //then parse it to Int 
int temp2 = temp * 2; //profit 100% so *2 
cash += temp2 //Add the amount to cash 
btnCashCurrency.setText(cash + " $"); 
相關問題