我是编码的新手,我觉得这写得不好。如何减少此代码的重复性?有没有更好的方法通过editText字段将数据设置到模型对象?
mVarietyField = v.findViewById(R.id.varietyInput);
mVarietyField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mMalt.setVariety(s.toString());
}
@Override
public void afterTextChanged(Editable s) {
}
});
mColorField = v.findViewById(R.id.colorInput);
mColorField.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
mMalt.setColor(Double.parseDouble(s.toString()));
}
@Override
public void afterTextChanged(Editable s) {
}
});