How Can I Manage Count Of Swiped Cards?
I'm implementing Swipe stack demo from here. Now I want track progress of swiped cards. I already made my own logic, and it's working pretty fine. but I've one more functionality,
Solution 1:
Hold a global variable and increment it on SwipeLeft
and SwipeRight
callback
privateinttotalCardsSwiped=0;
@OverridepublicvoidonViewSwipedToLeft(int position) {
totalCardsSwiped++; }
@OverridepublicvoidonViewSwipedToRight(int position) {
totalCardsSwiped++; }
Solution 2:
Why are you doing this in swiped callback methods?
mCurrentCardPosition = position + 2;
I think here is the problem.
or you can call this setCurrentCardPosition() method with the current position
@OverridepublicvoidonViewSwipedToLeft(int position) {
mCurrentCardPosition = position + 2;
setCurrentCardPosition(position);
lastSwipedPosition = position + 1;
changePreviousButtonStatus(0);
}
@OverridepublicvoidonViewSwipedToRight(int position) {
mCurrentCardPosition = position + 2;
setCurrentCardPosition(position);
lastSwipedPosition = position + 1;
changePreviousButtonStatus(0);
}
Edited
int currentPosition = 1;
After Adding Data in list
txtCardProgress.setText("1 out of " + mData.size());
in onClick
@Override
publicvoidonClick(View v) {
if (v.equals(mButtonLeft)) {
swipedLastPosition = swipedLastPosition - 1;
currentPosition =currentPosition -1;
if (swipedLastPosition >= 0) {
mTempData.clear();//clear all datafor (int i = swipedLastPosition; i < mData.size(); i++) {
mTempData.add(mData.get(i));
}
mSwipeStack.resetStack();
if (swipedLastPosition == 0) {
Toast.makeText(this, "hide back button", Toast.LENGTH_SHORT).show();
}
currentPosition =currentPosition -1;
setCardProgress(currentPosition);
} else {
swipedLastPosition = 0;
currentPosition = 0;
setCardProgress(currentPosition);
}
} elseif (v.equals(mButtonRight)) {
mSwipeStack.swipeTopViewToRight();
} elseif (v.equals(mFab)) {
swipedLastPosition = 0;
mTempData.clear();
mTempData.addAll(mData);
mSwipeStack.resetStack();
setCardProgress(swipedLastPosition);
}
Callback Methods
@OverridepublicvoidonViewSwipedToRight(int position) {
swipedLastPosition = position + 1;
setCardProgress(position);
}
@OverridepublicvoidonViewSwipedToLeft(int position) {
swipedLastPosition = position;
setCardProgress(position);
}
Update Progress method
voidsetCardProgress(int position){
if (position == mData.size()-1) {
currentPosition = mData.size();
txtCardProgress.setText(currentPosition + " out of " + mData.size());
} else {
currentPosition++;
txtCardProgress.setText(currentPosition + " out of " + mData.size());
}
}
Post a Comment for "How Can I Manage Count Of Swiped Cards?"