I am the beginner of the Android SDK programming.
What I have is,a calculator that doesn't show decimals when i press calculate button and is there if there is any way to do it?Also crashes if I didn't fill the EditText.
Button cal;
EditText n1,n2,n3;
TextView answer;
int x,y,r,z;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
answer = (TextView)findViewById(R.id.res);
n1 = (EditText)findViewById(R.id.n1);
n2 = (EditText)findViewById(R.id.n2);
n3 = (EditText)findViewById(R.id.n3);
cal = (Button)findViewById(R.id.calc);
cal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
x=Integer.parseInt(n1.getText().toString());
y=Integer.parseInt(n2.getText().toString());
z=Integer.parseInt(n3.getText().toString());
r=(x+y+z)/3;
answer.setText("" + r);
}
});