Untitled
unknown
java
3 years ago
1.4 kB
2
Indexable
Never
public class MainActivity extends AppCompatActivity { private Integer result = 0; private Integer number; private TextView numberTW; private TextView resultTW; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); this.numberTW = (TextView) findViewById(R.id.tempNo); this.resultTW = (TextView)findViewById(R.id.result); this.number = Integer.valueOf(numberTW.getText().toString()); } public void subtract(View view){ this.number = this.number - 1; this.numberTW.setText(this.number.toString()); } public void add(View view){ this.number = this.number + 1; this.numberTW.setText(this.number.toString()); } public void clear(View view){ this.number = 0; this.numberTW.setText(this.number.toString()); this.result = 0; this.resultTW.setText(this.result.toString()); resultTW.setBackgroundResource(R.color.black); resultTW.setTextColor(Color.WHITE); } public void calculate(View view){ this.result = this.result + this.number; this.resultTW.setText(this.result.toString()); resultTW.setBackgroundResource(R.color.white); resultTW.setTextColor(Color.BLACK); } }