I have a class:
public class TextViewAttachedProperties {
public static final String NAMESPACE = "http://schemas.android.com/apk/lib/com.zworks.mvvmandroid";
private static final Handler uiHandler = new Handler(Looper.getMainLooper());
private static final String DATA_CONTEXT = "DataContext";
private static final String TEXT = "Text";
private static final Listener<PropertyChangedEventArgs<String>> textChanged = new Listener<PropertyChangedEventArgs<String>>() {
@Override
public void onEvent(final PropertyChangedEventArgs<String> args) {
final TextView element = (TextView) args.getSource();
if (element != null && args.getNewValue() != null)
uiHandler.post(new Runnable() {
@Override
public void run() {
element.setText(args.getNewValue());
}
});
}
};
// This two statements have side effects I'm counting on to execute
private static final AttachedProperty<Object> dataContext = AttachedProperty
.newProperty(DATA_CONTEXT, NAMESPACE, TextView.class, null);
private static final AttachedProperty<String> text = AttachedProperty
.newProperty(TEXT, NAMESPACE, TextView.class, "", textChanged);
}
And the problem is it is only run if I instantiate that class.
How can I force it to be run no matter what?