I’m attempting to use IF THEN to add to and from integers in code:
one.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
subtotal = 1;
if (variable1==1) (counter + 1)
else if (variable1==2) then (counter + 1);
display.setText("Your total is" + counter);
}
});
But i get errors in my formatting i think.. =/
Many Thanks!
You should use curly brackets
{}.Also, saying
counter + 1doesn’t make much sense. I’m sure you meancounter += 1, which can be written ascounter++, because you’re only adding one.Also, since the body of the
ifs are the same, you can have both expressions in the sameif.