I have a toolbar in my Android LibGDX game which has various fields that need updating. Instead of hard coding which fields get updated with whichever variables, I want to create a mapping, so that fields are linked to a variable, and updated dynamically. However, I'm having a problem creating a bind to the variable itself rather than its value.
First I override the toolbar Draw method, so I can access any bindings I've assigned:
@Override
public void draw(SpriteBatch batch, float parentAlpha) {
//On each draw, check list of field/value bindings to update
for (UiToolBarFieldBinder binding : fieldBindings) {
String sValue = binding.boundValue;
((Label)binding.boundField).setText(sValue);
}
super.draw(batch, parentAlpha);
}
both boundValue and boundField are Objects in UiToolBarFieldBinder.
I assign the bind like so (with a Label Object and a String):
fieldBindings.add(new UiToolBarFieldBinder(lblFirstBar, myResources.AResourceValue));
This is where the problem is. I don't want to pass the String value to the bind, I want to pass the variable itself so that it regets the value in the Override Draw() method.
FYI, here is the structure of UiToolBarFieldBinder:
public class UiToolBarFieldBinder {
Object boundField;
Object boundValue;
public UiToolBarFieldBinder(Object field, Object value) {
boundField = field;
boundValue = value;
}
}
I might be making this overly complex but I can't see the solution immediately. Any help would be appreciated, cheers.
J