Question

I am working with Android SwipeListview in which i need to show one of the list item in a swipeListview should be in open position while the activity starts. I used code from following website https://github.com/47deg/android-swipelistview. I also found few answers in SwipeListView by 47degree: swipe first item programmatically: but it is not useful for me. Please help me i am struct with it. Some piece of code for your reference is

swipeFrontView = (View) view.findViewById(R.id.front);

    if (Build.VERSION.SDK_INT >= 11) {
        swipeListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        swipeListView
                .setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

                    @Override
                    public void onItemCheckedStateChanged(ActionMode mode,
                            int position, long id, boolean checked) {
                        mode.setTitle("Selected ("
                                + swipeListView.getCountSelected() + ")");
                    }

                    @Override
                    public void onDestroyActionMode(ActionMode mode) {
                        swipeListView.unselectedChoiceStates();
                    }

                    @Override
                    public boolean onActionItemClicked(ActionMode mode,
                            android.view.MenuItem item) {
                        return false;
                    }

                    @Override
                    public boolean onCreateActionMode(ActionMode mode,
                            android.view.Menu menu) {
                        return false;
                    }

                    @Override
                    public boolean onPrepareActionMode(ActionMode mode,
                            android.view.Menu menu) {
                        return false;
                    }
                });
    }

    swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {
        @Override
        public void onOpened(int position, boolean toRight) {
        }

        @Override
        public void onClosed(int position, boolean fromRight) {
        }

        @Override
        public void onListChanged() {
        }

        @Override
        public void onMove(int position, float x) {
        }

        @Override
        public void onStartOpen(int position, int action, boolean right) {

            Log.d("swipe open", String.format("onStartOpen %d - action %d",
                    position, action));
        }

        @Override
        public void onStartClose(int position, boolean right) {
            Log.d("swipe", String.format("onStartClose %d", position));
        }

        @Override
        public void onClickFrontView(int position) {
            Log.d("swipe", String.format("onClickFrontView %d", position));
        }

        @Override
        public void onClickBackView(int position) {
            Log.d("swipe", String.format("onClickBackView %d", position));
        }

        @Override
        public void onDismiss(int[] reverseSortedPositions) {
            /*
             * for (int position : reverseSortedPositions) {
             * data.remove(position); } adapter.notifyDataSetChanged();
             */
        }

    });

I used for animation from a library package

private void generateRevealAnimate(final View view) {
    ViewPropertyAnimator.animate(view).translationX(700).setDuration(500)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {

                }
            });
}

private void generateCloseAnimate(final View view) {
    ViewPropertyAnimator.animate(view).translationX(500).setDuration(500)
            .setListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                }
            });
Was it helpful?

Solution

Try listView.openAnimate(int position), where 'position' is the position you want to open swipe automatically, when activity starts.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top