Bret
Bret

Reputation: 2291

updating Label text within a Table through actors/cells within a GestureListener

Perhaps I'm simply going about this the wrong way ...

However, I'd simply like to change the text within a specific Label based on the direction of a GestureListener.fling(). I've kept both the Screen and GestureListener implementations within the same class in order to reduce possible trivial nonsense for this question:

public class TestScreen implements Screen, InputProcessor, GestureDetector.GestureListener {

In the show() method, I have the following:

Label heading = new Label("1ST", skin);
heading.setName("heading");
table.addActor(heading);

In the fling() method, I have the following:

Label l = table.findActor("heading");
l.setText("2ND");

However, the text within that label does not change. I've attempted to add the following line to the fling() method and it returns successful, but the text still does not update.

table.swapActors(table.getActor("heading"), l);

In an effort to be thorough, I've attempted the following to no avail:

SnapshotArray<Actor> children = table.getChildren();
int i = children.indexOf(l, false);
children.set(i, l);

and this ...

((Label)children.get(i)).setText(l.getText());

I even went as far as changing the initial .addActor() to just .add() in order for the table's cells to get created/populated - then attempted to modify the values of the table cells within the fling() method ...

Cell c = table.getCell(l);
c.setActor(l);

and this too ...

Array<Cell> cells = table.getCells();
int i = cells.indexOf(c, true);
cells.get(i).setActor(l);

Nothing appears to update the text visually on the screen - however, if I step through the debugger, then the table's actor/cell text appears to be updated ... but the text shown on the screen is always unchanged ... there is bound to be something that I'm missing here ...

Upvotes: 1

Views: 956

Answers (1)

Jonathan Kittell
Jonathan Kittell

Reputation: 7493

Try to call .invalidate() on the label - that should force it to update to the changed text.

The invalidate method invalidates this actor's layout, causing layout() to happen the next time validate() is called. This method should be called when state changes in the actor that requires a layout but does not change the minimum, preferred, maximum, or actual size of the actor (meaning it does not affect the parent actor's layout).

Upvotes: 1

Related Questions