private TextWatcher billEditTextWatcher = new TextWatcher()
{
// called when the user enters a number
@Override
public void onTextChanged(CharSequence s, int start,
int before, int count)
{
// convert billEditText's text to a double
try
{
currentBillTotal = Double.parseDouble(s.toString());
} // end try
catch (NumberFormatException e)
{
currentBillTotal = 0.0; // default if an exception occurs
} // end catch
// update the standard and custom tip EditTexts
updateStandard(); // update the 10, 15 and 20% EditTexts
updateCustom(); // update the custom tip EditTexts
} // end method onTextChanged
@Override
public void afterTextChanged(Editable s)
{
} // end method afterTextChanged
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
} // end method beforeTextChanged
}; // end billEditTextWatcher
这是一个专业的小费计算器应用程序的代码片段。有人能解释一下这是如何工作的吗?
通常,我只需编写以下内容即可创建一个新对象。
TextWatcher billEditTextWatcher = new TextWatcher();
我知道private的作用是什么,但是在创建新对象时为什么会有方法呢?它基本上是按照字面意思做吗?覆盖TextWatcher类中的原始方法?
希望我的问题表达清楚了,因为我很困惑。
提前感谢!