'Global Variable and operator - between two Global variables
I am new to android studio and programming. I am facing an issue. I have decleared two Global variables here.
package com.example.letsbid;
public class GlobalVariable
{
public static int balance = 100;
private static int deduction=15;
}
Then I assign the value of that Global variable to a text view
tv_balance.setText(String.valueOf(GlobalVariable.balance));
now I want whenever user click on a specific button that balance should reduce 15 points. for example if it is 100 it should become 85, if its 60 it should become 45. For that I am trying this
btn_515.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// error in here following code, i tried balance=balance-15;
// I tried balance=balance-deduction;
// I tried balance==balance+""-deduction+"";
balance==balance-deduction;
tv_balance.setText(String.valueOf(GlobalVariable.balance));
Intent intent = new Intent(BalanceActivity.this, LotteryActivity.class);
startActivity(intent);
}
});
But it shows error operator - cannot be applied to Global variable
Now how can I apply that - to that so that everty time user click on btn_515, 15 should be deducted from his balance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
