I want to toast an integer in an IF condition about "isChecked" action. Now, when I execute I'm getting wrong number.
- For the 'if', the value of 5 (inherits from etSNum) toast 0.95
- For the 'else if', the value of 5 (inherits from etSNum) toast -5
code:
Button btnWaitress;
EditText etSalaryWaitress;
EditText etSalaryBartender;
//------------
RadioButton rbPercentage;
RadioButton rbShekel;
int HafrashaP;
int HafrashaS;
int etSWNum;
String strHafPer;
String strHafShek;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
btnWaitress =(Button)findViewById(R.id.btnWaitress);
etSalaryWaitress = (EditText) findViewById(R.id.etSalaryWaitress);
etSWNum = Integer.parseInt(etSalaryWaitress.getText().toString());
etSalaryBartender = (EditText) findViewById(R.id.etSalaryBartender);
//-----------
rbPercentage = (RadioButton)findViewById(R.id.rbPercentage);
rbShekel = (RadioButton)findViewById(R.id.rbShekel);
}
public void onClickWait (View v) {
if (rbPercentage.isChecked()) {
HafrashaP = 1 - (etSWNum / 100);
strHafPer= Integer.toString(HafrashaP);
Toast.makeText(settings.this, strHafPer, Toast.LENGTH_SHORT).show();
} else if (rbShekel.isChecked()) {
HafrashaS = - etSWNum;
strHafShek= Integer.toString(HafrashaS);
Toast.makeText(settings.this, strHafShek, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(settings.this, "XXXXXXX", Toast.LENGTH_SHORT).show();
}
}
}