Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwipeListView by 47degree: swipe first item programmatically

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?

Update

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.

Update 2

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.

like image 380
Emil Adz Avatar asked Nov 18 '25 20:11

Emil Adz


1 Answers

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);
    }
};
like image 139
Vetalll Avatar answered Nov 21 '25 08:11

Vetalll