zihadrizkyef

Square Area

May 29th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.06 KB | None | 0 0
  1. package zihadrizkyef.math.luaspersegi;
  2.  
  3. import android.support.v7.app.AppCompatActivity;
  4. import android.os.Bundle;
  5. import android.text.Editable;
  6. import android.text.TextWatcher;
  7. import android.util.Log;
  8. import android.widget.EditText;
  9. import android.widget.TextView;
  10.  
  11. public class MainActivity extends AppCompatActivity {
  12.  
  13.     final EditText etWidth = (EditText) findViewById(R.id.etWidth);
  14.     final EditText etHeight = (EditText) findViewById(R.id.etHeight);
  15.     final TextView tvResult = (TextView) findViewById(R.id.tvResult);
  16.  
  17.     void proccess() {
  18.         String strWidth = etWidth.getText().toString();
  19.         String strHeight = etHeight.getText().toString();
  20.  
  21.         if (!strWidth.equals("") && !strHeight.equals("")) {
  22.             int intWidth = Integer.parseInt(strWidth);
  23.             int intHeight = Integer.parseInt(strHeight);
  24.             int result = intWidth*intHeight;
  25.  
  26.             tvResult.setText(String.valueOf(result));
  27.         }
  28.     }
  29.  
  30.     @Override
  31.     protected void onCreate(Bundle savedInstanceState) {
  32.         super.onCreate(savedInstanceState);
  33.         setContentView(R.layout.activity_main);
  34.  
  35.         etWidth.addTextChangedListener(new TextWatcher() {
  36.             @Override
  37.             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  38.  
  39.             }
  40.  
  41.             @Override
  42.             public void onTextChanged(CharSequence s, int start, int before, int count) {
  43.  
  44.             }
  45.  
  46.             @Override
  47.             public void afterTextChanged(Editable s) {
  48.                 proccess();
  49.             }
  50.         });
  51.  
  52.         etHeight.addTextChangedListener(new TextWatcher() {
  53.             @Override
  54.             public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  55.                
  56.             }
  57.  
  58.             @Override
  59.             public void onTextChanged(CharSequence s, int start, int before, int count) {
  60.  
  61.             }
  62.  
  63.             @Override
  64.             public void afterTextChanged(Editable s) {
  65.                 proccess();
  66.             }
  67.         });
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment