Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zihadrizkyef.math.luaspersegi;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.text.Editable;
- import android.text.TextWatcher;
- import android.util.Log;
- import android.widget.EditText;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- final EditText etWidth = (EditText) findViewById(R.id.etWidth);
- final EditText etHeight = (EditText) findViewById(R.id.etHeight);
- final TextView tvResult = (TextView) findViewById(R.id.tvResult);
- void proccess() {
- String strWidth = etWidth.getText().toString();
- String strHeight = etHeight.getText().toString();
- if (!strWidth.equals("") && !strHeight.equals("")) {
- int intWidth = Integer.parseInt(strWidth);
- int intHeight = Integer.parseInt(strHeight);
- int result = intWidth*intHeight;
- tvResult.setText(String.valueOf(result));
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- etWidth.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- proccess();
- }
- });
- etHeight.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- @Override
- public void afterTextChanged(Editable s) {
- proccess();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment