【发布时间】:2014-05-08 04:41:10
【问题描述】:
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();
我了解私人做什么。但是新对象的创建过程中怎么会有方法呢?它基本上是在做它所说的吗?覆盖 TextWatcher 类中的原始方法?
我希望这个问题有意义,因为我很困惑。
提前致谢!
【问题讨论】:
标签: java android object textwatcher