Frankey
Frankey

Reputation: 336

ClickListener only works for elements in Table Libgdx

I have a table extended main class (table_A). Inside table_A class i have a method which function is to add new table (table_b) into my table_A (for achieving scrollpane result), at the same time assign click listener to the table_b.

I though by adding clicklistener (ck) to table_b will makes table_b detectable. However, only the elements in the table_b able to make detection from clicklistener.

Please help

My table_A adding table function as follow:

 public void addRow(Table newRow){
    scrollTable.row();
    scrollTable.add(newRow).width(newRow.getWidth()).pad(10);
    newRow.addListener(ck);
    newRow.debug();
    newRow.setName(stage++ +"");
}

My debug table goes as:

enter image description here

My table_b codes goes as:

  add(challengeLabel).colspan(10).expandX().align(Align.left).fill();
        row();

        add(star1).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth).expandX().fillX().align(Align.right);
        add(star2).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth);
        add(star3).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth);
        add(star4).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth);
        add(star5).colspan(1).size(starSpaceWidth, star1.getHeight() / star1.getWidth() * starSpaceWidth);

Upvotes: 0

Views: 62

Answers (1)

MrStahlfelge
MrStahlfelge

Reputation: 1791

If you take a look in Table's constructor, you see this line:

setTouchable(Touchable.childrenOnly);

It is causing your troubles. Change it for your table_B.

Upvotes: 3

Related Questions