aaronbond / Swipe-Deck

A Tinder style Swipeable deck view for Android
MIT License
797 stars 158 forks source link

Is there any way to skip top card_ #31

Closed beyti closed 8 years ago

beyti commented 8 years ago

Is there any way to remove top card without swiping, programmatically?

BTW, thanks for the repo, really nice.

aaronbond commented 8 years ago

I'm not exactly sure what effect you're trying to achieve, but you could remove the top card from the adapter and then call notifyDataSetChanged() on it.

I suspect that's not exactly what you're after, are you wanting to be able to remove the top card with a different animation than swiping?

beyti commented 8 years ago

I'm exactly trying to do that, but couldn't find a way to get top card.

adapter = new CustomSwipeDeckAdapter(getContext(), R.id.content, cardList);
cardStack.setAdapter(adapter);

tried below:

CustomItem item = adapter.getItem(0); //this gets the top card, but it doesnt get removed after remove operation, card stands still on application
adapter.remove(item);
adapter.notifyDataSetChanged();

or below:

cardList.remove(0);
adapter.notifyDataSetChanged();

and many things like this but couldn't figure out the right way.

beyti commented 8 years ago

By the way, when in a cardSwipedLeft or cardSwipedRight method, cardList.get(0) doesn't always gets the item in order, I mean it can skip some items in list which cripples the logic.

Is it possible or am I doing something wrong?

The testing I've done is like below:

public void cardSwipedLeft(int position) {
ContentDto itemToRemove = cardList.get(0);
cardList.remove(itemToRemove);
adapter.notifyDataSetChanged();
}

itemToRemove should be the card showing on top but after a few swipes, it can skip some item, forexample while the card on top saying "value 1", after swiping right, itemToRemove is indeed the first item in cardList however "value 1" item is the second indexed item in cardList. Shouldn't the adapter take them in order?

aaronbond commented 8 years ago

https://github.com/aaronbond/SwipeDeck2 << if you're still having issues after moving to this version please raise another issue over there.