Android SwipeListView用法
来源:互联网 发布:淘宝云客服怎么联系 编辑:程序博客网 时间:2024/05/25 01:36
最近在做一个项目,需要用到像IPone删除的效果,即在item上左滑弹出删除的按钮。找了一些资料,发现在github上有个SwipeListView的项目可以实现这个功能。下面介绍一下SwipeListView的使用方法。
1、下载library和demo:https://github.com/47deg/android-swipelistview。
2、下载依赖lib nineoldandroids-2.4.0.jar:https://github.com/JakeWharton/NineOldAndroids/downloads。
3、解压SwipeListView文件,在eclipse里导入swipeListView的lib项目,把nineoldandroids-2.4.0.jar和android-support-v4.jar加入到libs下面。
4、导入demo项目,引入swipeListView库。
5、swipeListView的用法,在布局文件里:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:swipe="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/background_app" android:orientation="vertical" > <com.fortysevendeg.swipelistview.SwipeListView android:id="@+id/example_lv_list" android:layout_width="fill_parent" android:layout_height="wrap_content" android:listSelector="#00000000" swipe:swipeBackView="@+id/back" swipe:swipeCloseAllItemsWhenMoveList="true" swipe:swipeDrawableChecked="@drawable/choice_selected" swipe:swipeDrawableUnchecked="@drawable/choice_unselected" swipe:swipeFrontView="@+id/front" swipe:swipeMode="both" /></LinearLayout>item布局文件:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:id="@+id/back" style="@style/ListBackContent" android:tag="back" > <Button android:id="@+id/example_row_b_action_1" style="@style/ListButtonAction" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/open" /> <Button android:id="@+id/example_row_b_action_2" style="@style/ListButtonAction" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/googlePlay" /> <Button android:id="@+id/example_row_b_action_3" style="@style/ListButtonAction" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/uninstall" /> </LinearLayout> <RelativeLayout android:id="@+id/front" style="@style/ListFrontContent" android:orientation="vertical" android:tag="front" > <ImageView android:id="@+id/example_row_iv_image" style="@style/ListImage" /> <TextView android:id="@+id/example_row_tv_title" style="@style/ListTitle" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/example_row_iv_image" /> <TextView android:id="@+id/example_row_tv_description" style="@style/ListDescription" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_below="@id/example_row_tv_title" android:layout_toRightOf="@id/example_row_iv_image" /> </RelativeLayout></FrameLayout>代码:
adapter = new PackageAdapter(this, data); swipeListView = (SwipeListView) findViewById(R.id.example_lv_list); 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 boolean onActionItemClicked(ActionMode mode, MenuItem item) { int id = item.getItemId(); if (id == R.id.menu_delete) { swipeListView.dismissSelected(); return true; } return false; } @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.menu_choice_items, menu); return true; } @Override public void onDestroyActionMode(ActionMode mode) { swipeListView.unselectedChoiceStates(); } @Override public boolean onPrepareActionMode(ActionMode mode, 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", 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(); } }); swipeListView.setAdapter(adapter);
以上就是SwipeListView的用法。
注:设置swipeListView的模式要在adapter更新数据之后。
0 0
- Android SwipeListView用法
- SwipeListView的简单用法
- android-swipelistview使用说明
- SwipeListView滑动删除Android
- SwipeListView
- SwipeListView
- android-swipelistview项目打包测试
- android库SwipeListView的使用
- android 仿微信侧滑删除SwipeListView实例
- android SwipeListView开源项目导入
- android-swipelistview 导入和d使用
- android SwipeListView开源项目导入
- android--SwipeListView实现ListView滑动删除效果
- android开发之SwipeListView的使用
- 关于android-swipelistview的开源项目的使用
- Android SwipeListView 实现ListView的滑动删除效果
- Android SwipeListView 实现ListView的滑动删除效果
- android开发之开源项目SwipeListView之使用
- 使用亚马逊 CloudFront 进行 RTMP 的 CDN 加速
- 将VS2010默认Unicode编码设置为ANSI编码
- JavaSE_util+其他核心类
- 类名.class与对象.getClass的区别
- 回首13,展望14
- Android SwipeListView用法
- 主机字节序和网络字节序
- Crystal Report 在 VS 2010 中的使用
- 《软件开发》阅读笔记二
- android webview 去掉多点触控 去掉放大缩小
- Android访问网络,使用HttpURLConnection还是HttpClient?
- Android动画学习笔记-Android Animation
- 总结整理时下流行的浏览器User-Agent大全
- xfire1.2.6在weblogic平台上传输二进制数据的时候报错误的解决方案