I have and android layout with two edittexts one for Qty and one for rate and a textview for total amount. Now 开发者_StackOverflow社区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?
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.
精彩评论