Created
June 22, 2013 07:13
-
-
Save hschmitt/5836175 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.android.tareaderoxana; | |
import android.os.Bundle; | |
import android.app.Activity; | |
import android.text.Editable; | |
import android.text.TextWatcher; | |
import android.view.Menu; | |
import android.widget.EditText; | |
public class MainActivity extends Activity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
// Event Change de numero 1 | |
EditText editText1 = (EditText) findViewById(R.id.editText1); | |
editText1.addTextChangedListener(new TextWatcher() { | |
public void afterTextChanged(Editable s) { | |
EditText editText2 = (EditText) findViewById(R.id.editText2); | |
if (!editText2.hasFocus()) { | |
int product; | |
if (s.length() == 0) { | |
product = 0; | |
} else { | |
product = Integer.parseInt(s.toString()) * 5; | |
} | |
editText2.setText(Integer.toString(product)); | |
} | |
} | |
@Override | |
public void beforeTextChanged(CharSequence arg0, int arg1, | |
int arg2, int arg3) { | |
} | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, | |
int count) { | |
} | |
}); | |
// Para el edittext2 | |
EditText editText2 = (EditText) findViewById(R.id.editText2); | |
editText2.addTextChangedListener(new TextWatcher() { | |
public void afterTextChanged(Editable s) { | |
EditText editText1 = (EditText) findViewById(R.id.editText1); | |
if (!editText1.hasFocus()) { | |
int division; | |
if (s.length() == 0 || s.toString().equals("0")) { | |
division = 0; | |
} else { | |
division = (Integer.parseInt(s.toString()) / 5); | |
} | |
editText1.setText(Integer.toString(division)); | |
} | |
} | |
@Override | |
public void beforeTextChanged(CharSequence arg0, int arg1, | |
int arg2, int arg3) { | |
} | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, | |
int count) { | |
} | |
}); | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.activity_main, menu); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment