yuyakaido / CardStackView

📱Tinder like swipeable card view for Android
Apache License 2.0
2.37k stars 448 forks source link

Add CardStackListener in Java #250

Closed HellAmbro closed 5 years ago

HellAmbro commented 5 years ago

Hi, i'm trying to set CardStackListener to my CardStackView but i can't find method such as addCardStackListener or setCardStackListener. I'm using Java and i don't know Kotlin. How can i set this listener? Thanks

HellAmbro commented 5 years ago

I've looked at the source code and i found the solution.

imalpasha commented 5 years ago

Hi Wosham, Do u mind sharing the source code for this solution? Thanks :)

HellAmbro commented 5 years ago

`This is my code,i hope it's helpful

private MyAdapter mAdapter;
private CardStackView mCardStackView;

private void initCardStack() {
    mAdapter = new MyAdapter(this);

    mCardStackView = findViewById(R.id.card_stack_view);
    mCardStackView.setAdapter(mAdapter);

    CardStackLayoutManager manager = new CardStackLayoutManager(this, new CardStackListener() {
        @Override
        public void onCardDragging(Direction direction, float ratio) {
        }

        @Override
        public void onCardSwiped(Direction direction) {
        }

        @Override
        public void onCardRewound() {
        }

        @Override
        public void onCardCanceled() {
        }

        @Override
        public void onCardAppeared(View view, int position) {

        }

        @Override
        public void onCardDisappeared(View view, int position) {

        }
    });

    mCardStackView.setLayoutManager(manager);
}

} `