如何在swipelistview项目中只向左滑动

时间:2015-01-25 14:19:18

标签: android listview

  

我使用了这个图书馆https://github.com/47deg/android-swipelistview   在项目我想要行只向左滑动,不允许滑动行   与wiche其他当点击行不刷卡并打开新活动

 public class Aragh extends Activity {
        SwipeListView swipelistview;
        ItemAdapter adapter;
        List<ItemRow> itemData;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.aragh);
             swipelistview=(SwipeListView)findViewById(R.id.example_swipe_lv_list); 

                itemData=new ArrayList<ItemRow>();
                adapter=new ItemAdapter(this,R.layout.custom_row,itemData);



                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", 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));


                        swipelistview.openAnimate(position); //when you touch front view it will open


                    }

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

                        swipelistview.closeAnimate(position);//when you touch back view it will close
                    }

                    @Override
                    public void onDismiss(int[] reverseSortedPositions) {

                    }

                });

                //These are the swipe listview settings. you can change these
                //setting as your requirement 
                swipelistview.setSwipeMode(SwipeListView.SWIPE_MODE_RIGHT); // there are five swiping modes
                swipelistview.setSwipeActionLeft(SwipeListView.SWIPE_ACTION_DISMISS); //there are four swipe actions 
                swipelistview.setSwipeActionRight(SwipeListView.SWIPE_ACTION_DISMISS);
                swipelistview.setOffsetLeft(convertDpToPixel(0f)); // left side offset
                swipelistview.setOffsetRight(convertDpToPixel(80f)); // right side offset
                swipelistview.setAnimationTime(500); // Animation time
                swipelistview.setSwipeOpenOnLongPress(false); // enable or disable SwipeOpenOnLongPress

                swipelistview.setAdapter(adapter);


                for(int i=0;i<10;i++)
                {
                    itemData.add(new ItemRow("Swipe Item"+i,getResources().getDrawable(R.drawable.ic_launcher) ));

                }

                adapter.notifyDataSetChanged();
            }

            public int convertDpToPixel(float dp) {
                DisplayMetrics metrics = getResources().getDisplayMetrics();
                float px = dp * (metrics.densityDpi / 160f);
                return (int) px;
            }



        }

2 个答案:

答案 0 :(得分:1)

我建议用XML格式化。

您在SwipeListView标记中添加

swipe:swipeMode="left"

它会将您的滑动模式锁定在左侧。 你可以选择 - 左/右/两者。

答案 1 :(得分:0)

您只需将swipe:swipeMode="left"放入<....SwipeListView /&gt;在您的xml布局中,只允许向左滑动