I have two EditText fields,whenever i enter the value in one editText,the other should display the answer for one calculation that taking the value of first editText,Iam unsure how to do this,thanks 开发者_C百科in advance(android)
you can do this by using EditText's onKeyListener event, you can also show result when specific key is pressed
Use a TextWatcher and update the content of the target on each change.
The best method for this question is .addTextChangedListener()
you can use it by this code:
editText_1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
try {
//Your Codes
} catch (Exception e) {
// if editText_1 become null or ""
editText_1.setText("0");
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
精彩评论