Reputation: 41099
I would like to swipe the first item on the SwipeListView on Activity
start up to show the user that the SwipeListView
is swipe-able.
How can I perform this action programmatically with this UI element?
I tried to use the
swipeListView.openAnimate(position)
that was proposed here in the answer, but for some reason even after I populate the adapter with data-items... when I debug and reach this code section the swipeListView doesn't see item in it, and fails with NullPointerException
.
Well, I realized that the reason there were no items in the adapter because it's not yet created in onCreate
, so I moved this code to method:
public void onWindowFocusChanged(boolean hasFocus){}
of my activity, now it runs but still fails on the following method of the SwipeListView
library:
private void resetCell() {
if (downPosition != ListView.INVALID_POSITION) {
if (swipeCurrentAction == SwipeListView.SWIPE_ACTION_CHOICE) {
backView.setVisibility(View.VISIBLE);
}
frontView.setClickable(opened.get(downPosition));
frontView.setLongClickable(opened.get(downPosition));
frontView = null;
backView = null;
downPosition = ListView.INVALID_POSITION;
}
}
The reason for this is that when this method is running the frontView
object is never set and those it null.
Upvotes: 3
Views: 2247
Reputation: 41099
I have actually went and recreated the used animation in the library just for the instance of the Showcase, so what I did was:
private void generateRevealAnimate(final View view) {
animate(view)
.translationX(-520)
.setDuration(500)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {}
});
}
private void generateCloseAnimate(final View view) {
animate(view)
.translationX(0)
.setDuration(500)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {}
});
}
And then just run them one after another on the desired view:
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run()
{
generateRevealAnimate(firstFrontView);
handler.postDelayed(new Runnable() {
@Override
public void run()
{
generateCloseAnimate(firstFrontView);
}
}, 1400);
}
}, 1400);
Upvotes: 1
Reputation: 3357
Check the source code!
SwipeListViewTouchListener sets the frontView. setFrontView()
is only being called in case of on touch down event. So either you somehow fake a touch event for this view or you fork the library and update it to your needs.
Upvotes: 1
Reputation: 3700
For openining the item you should use
swipeListView.openAnimate(position)
For closing the item you can use on of this:
swipeListView.closeAnimate(position);
swipeListView.closeOpenedItems();
Here is some code from working project:
private BaseSwipeListViewListener albumsLIstener = new BaseSwipeListViewListener() {
@Override
public void onClickFrontView(int position) {
if (albumsListsView.isOpened(position)) {
albumsListsView.closeAnimate(position);
} else albumsListsView.openAnimate(position);
}
@Override
public void onClickBackView(int position) {
if (albumsListsView.isOpened(position)) {
albumsListsView.closeAnimate(position);
} else albumsListsView.openAnimate(position);
}
};
Upvotes: 1