问题
I have and android layout with two edittexts one for Qty and one for rate and a textview for total amount. now what i want to do is change/update the total amount whenever the user changes the rate or quantity fields.
what is the edittext event i am looking for and can i set it from the layout xml properties like i can set OnClick?
回答1:
For this you have to set addTextChangedListener() to editText. Just as below:
editText.addTextChangedListener(this);// your activity has to implement TextWatcher interface
Then you have to override this method:
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
}
You can use any of this method as you need and change your relevant views text.
来源:https://stackoverflow.com/questions/4893638/what-is-the-event-when-and-edittext-is-updated