1

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

Jammo
  • 1,838
  • 4
  • 25
  • 39
  • I don't clearly understand what you're trying to do. But one of the limitations of Java is that there are no pointers for primitive types, even the Object versions of the primitives). You have to create your own mutable primitive wrapper class, or wrap it in an array. See this answer: http://stackoverflow.com/questions/4319537/how-do-i-pass-a-primitive-data-type-by-reference/4319581#4319581 – Tenfour04 Jan 23 '15 at 14:03

0 Answers0