Two number sum in Android Studio (JAVA)
package com.example.twonumbercalculate;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText n1 , n2;
TextView textView;
Button button2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
button2 = findViewById(R.id.button2);
n1 = findViewById(R.id.n1);
n2 = findViewById(R.id.n2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int sum = Integer.parseInt(n1.getText().toString()) + Integer.parseInt(n2.getText().toString());
textView.setText("This Two number sum is " + sum);
Toast.makeText(MainActivity.this, "Calculate completed", Toast.LENGTH_SHORT).show();
}
});
}
}
Comments
Post a Comment