Rahul Verma
Rahul Verma

Reputation: 2150

Scroll Listener on Scroll Pane Libgdx

I am using a scroll pane to show a list of items. I want to add a Scroll Listener on the pane so that I can load more items Dynamically to the pane once it hits the bottom edge;

I tried to add an InputListener and override onScroll but is not working for me

Upvotes: 6

Views: 1981

Answers (2)

Rahul Verma
Rahul Verma

Reputation: 2150

I found another relevant solution which I would like to share :

ScrollPane scrollPane;
Table scrollTable
float lastScrollY = 0;
.
.
.
scrollTable = new Table();
this.scrollPane = new ScrollPane(scrollTable){
        @Override
        public void act(float delta) {
            super.act(delta);
            if(lastScrollY!=scrollPane.getScrollY()){
                lastScrollY = scrollPane.getScrollY();
                processScrolling();
            }

        }
    };

Upvotes: 3

Angel Angel
Angel Angel

Reputation: 21678

this is a simple test, I hope I understood your question

In Your Class.

..//
yourScrollPane.addListener(new EventListener() {

    @Override
    public boolean handle(Event event) {
        // TODO Auto-generated method stub

        System.out.println("Event % "+yourScrollPane.getScrollPercentY());

        if(yourScrollPane.getScrollPercentY() == 1f){
            addImageButton();
        }

        return false;
    }
});

}

private void addImageButton(){

    //Add actor in scroll
    yourTableInScrollPane.add(button2).row();
    yourTableInScrollPane.add(button3).row();
    yourTableInScrollPane.add(button4).row();

    //table.invalidate();
}

Upvotes: 3

Related Questions