我喜欢创建一个新对象,其中一个字段是另一个对象的引用。
UIViewObject是对象的类定义,oView是我想引用另一个对象的字段:
public class UIViewObject {
public View oView;
public Integer oEnabled;
public Integer oVisible;
public UIViewObject() {
oEnabled = UIAction.UISettingView.ENABLED;
oVisible = UIAction.UISettingView.VISIBLE;
}
public UIViewObject setObject(View OView) {
oView = OView;
return this;
}
public UIViewObject setObject(GL_TextView OView) {
oView = OView;
return this;
}
public UIViewObject setEnabled() {
oEnabled = UIAction.UISettingView.ENABLED;
return this;
}
public UIViewObject setDisabled() {
oEnabled = UIAction.UISettingView.DISABLED;
return this;
}
public UIViewObject setShow() {
oVisible = UIAction.UISettingView.VISIBLE;
return this;
}
public UIViewObject setHide() {
oVisible = UIAction.UISettingView.GONE;
return this;
}
public UIViewObject setObjectEnabled() {
oView.setEnabled(true);
return this;
}
public UIViewObject setObjectDisabled() {
oView.setEnabled(false);
return this;
}
public UIViewObject setObjectShow() {
oView.setVisibility(View.VISIBLE);
return this;
}
public UIViewObject setObjectHide() {
oView.setVisibility(View.GONE);
return this;
}
}
这是我创建对象的方式:
HashMap<String, UIViewObject> viewsAction = new HashMap<String,UIViewObject>();
public void setTextView_Finalized_Show() {
UIViewObject newO = new UIViewObject();
viewsAction.put("txvFinalized", newO.setObject(mUIInvoice.txvFinalized).setShow());
}
public void setTextView_Finalized_Hide() {
UIViewObject newO = new UIViewObject();
viewsAction.put("txvFinalized", newO.setObject(mUIInvoice.txvFinalized).setHide());
}
txvFinalized是一个公共变量,在newO创建时为null,但之后它获取值。我希望当txvFinalized在oNew中获取值时,oView的值会发生变化。
如何定义字段作为参考,例如txvFinalized?