利用swipelistview完成qq聊天列表右滑删除功能



开启阅读模式

利用swipelistview完成qq聊天列表右滑删除功能

  2538人阅读  评论(4)  收藏  举报
  分类:

转载请注明出处:http://blog.csdn.net/harryweasley/article/details/41413547


前言:前段时间,由于自己比较悠闲,没有什么工作上的事情所做,所以当时就想,何不做一下qq聊天列表的item右滑出现后面的视图,然后我就开始着手自己做,之后无意间发现了可以利用一个github开源项目swiplistview完成,但是当我查看那些swiplistview的相关文档时,很不全面,github官网上下载的和之前他们写的文档已经有所不同,所以在这里我就重新来写一下怎么使用swiplistview的准备阶段。

之前的文档都是说,当从官网上下载下来后,有两个文件,一个是lib:android-swiplistview,另一个是例子:SwipListViewExampleActivity,但是现在下载后,解压后是这样的


显然已经和之前的不一样了,现在的官网上是用了gradle来构造Android程序,但我以前根本没有接触过gradle,所以只能自己去找以前的那个swiplistview。当时我也是纠结了很久,自己翻墙出去,各种Google,最后终于找到了,swiplistview,我之后会全部上传,共享给大家。

下面是qq的效果图:


下面是我这个项目的效果图:


现在我们进入正题:

我们一共需要两个jar包,一个swiplistview,如图所示:这三个下载地址http://download.csdn.net/detail/harryweasley/8190519


1. 引入android-swipelistview库:导入开源库,用Import选项,然后Android选项下的“Existing Android Code Into Workspace”引入库;在这里将“copy projects into workspace”前面打钩哦

2.引入android-swipelistview的依赖库nineoldandroids-2.4.0.jar:建立一个libs文件夹,将nineoldandroids-2.4.0.jar拷贝到libs文件夹之下;

3.引入android-swipelistview的依赖内部库android-support-v4.jar:项目的Android Tools选项,“Add Support Library”来增加android-support-v4库;(注:如果找不到对应的support库,可以通过SDK Manager来进行下载)
4.编译android-swipelistview库的jar包:项目的Properties选项,Android选项,勾选"Is Library";
5.编译android-swipelistview项目,在项目的bin目录应该能看到android-swipelistview.jar包。


这样,我们就完成了swiplistview的库了。

然后我们自己建立一个Android程序SwipListView进行测试,建好后,开始导入库,项目的Properties选项,Android选项,Library框选择add按钮添加swipelistview.jar包;

这里需要注意:swipelistview这个lib必须和SwiplistView在同一工作区间,否则导入的包前面会有红叉。如图所示



我们可以看下官网上关于SwipListView的描述

If you decide to use SwipeListView as a view, you can define it in your xml layout like this:

    <com.fortysevendeg.swipelistview.SwipeListView
            xmlns:swipe="http://schemas.android.com/apk/res-auto"
            android:id="@+id/example_lv_list"
            android:listSelector="#00000000"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            swipe:swipeFrontView="@+id/front"
            swipe:swipeBackView="@+id/back"
            swipe:swipeActionLeft="[reveal | dismiss]"
            swipe:swipeActionRight="[reveal | dismiss]"
            swipe:swipeMode="[none | both | right | left]"
            swipe:swipeCloseAllItemsWhenMoveList="[true | false]"
            swipe:swipeOpenOnLongPress="[true | false]"
            swipe:swipeAnimationTime="[miliseconds]"
            swipe:swipeOffsetLeft="[dimension]"
            swipe:swipeOffsetRight="[dimension]"
            />
  • swipeFrontView - Required - front view id. 即ListView Item正常显示的控件Id,且必须与Item的布局文件中的控件id一样
  • swipeBackView - Required - back view id.  手指滑动时显示的,隐藏在FrontView后面,且必须与item的布局文件中控件Id一样
  • swipeActionLeft - Optional - left swipe action Default: 'reveal'  左滑的动作,默认reveal,即显示BackView,还有dismiss,choice会触发响应的方法。
  • swipeActionRight - Optional - right swipe action Default: 'reveal' 同上
  • swipeMode - Gestures to enable or 'none'. Default: 'both' 设置左滑、右滑、都支持
  • swipeCloseAllItemsWhenMoveList - Close revealed items on list motion. Default: 'true' 当滚动listview时,关闭所有展开的Item,最好不要设置为false,由于item的复用,false存在一些问题。
  • swipeOpenOnLongPress - Reveal on long press Default: 'true' 长按时触发显示
  • swipeAnimationTime - item drop animation time. Default: android configuration 动画时间长度
  • swipeOffsetLeft - left offset 左偏移量
  • swipeOffsetRight - right offset 右偏移量
上面是基本属性,下面开始上代码:

首先是activity_main.xml下的代码:

[java]  view plain copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <com.fortysevendeg.swipelistview.SwipeListView  
  8.         xmlns:swipe="http://schemas.android.com/apk/res-auto"  
  9.         android:id="@+id/example_lv_list"  
  10.         android:layout_width="fill_parent"  
  11.         android:layout_height="fill_parent"  
  12.         swipe:swipeActionLeft="reveal"  
  13.         swipe:swipeBackView="@+id/id_back"  
  14.         swipe:swipeCloseAllItemsWhenMoveList="true"  
  15.         swipe:swipeFrontView="@+id/id_front"  
  16.         swipe:swipeMode="left"  
  17.         swipe:swipeOffsetLeft="200dip"  
  18.         swipe:swipeOffsetRight="0dp"  
  19.         swipe:swipeOpenOnLongPress="true" />  
  20.   
  21. </RelativeLayout>  

接下来是itm.xml的代码:

[java]  view plain copy
  1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="60dp" >  
  5.   
  6.     <LinearLayout  
  7.         android:id="@+id/id_back"  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="match_parent"  
  10.         android:background="#ffcccccc"  
  11.         android:gravity="center|right" >  
  12.   
  13.         <Button  
  14.             android:id="@+id/id_remove"  
  15.             android:layout_width="60dp"  
  16.             android:layout_height="wrap_content"  
  17.             android:layout_gravity="center"  
  18.             android:layout_marginRight="4dp"  
  19.             android:background="@android:color/holo_green_light"  
  20.             android:text="Delete"  
  21.             android:textColor="#fff" >  
  22.         </Button>  
  23.     </LinearLayout>  
  24.   
  25.     <LinearLayout  
  26.         android:id="@+id/id_front"  
  27.         android:layout_width="match_parent"  
  28.         android:layout_height="match_parent"  
  29.         android:background="#ffffffff" >  
  30.   
  31.         <TextView  
  32.             android:id="@+id/id_text"  
  33.             android:layout_width="wrap_content"  
  34.             android:layout_height="wrap_content"  
  35.             android:layout_marginLeft="10dp"  
  36.             android:gravity="center_vertical"  
  37.             android:minHeight="?android:attr/listPreferredItemHeight"  
  38.             android:textAppearance="?android:attr/textAppearanceLarge"  
  39.             android:textColor="#000"  
  40.             android:textSize="25sp" >  
  41.         </TextView>  
  42.     </LinearLayout>  
  43.   
  44. </FrameLayout>  

这里要强调一下:对应布局的id和swipeListView中的frontView和backView的Id一致。

接下来是DataAdapter的代码

[java]  view plain copy
  1. package com.example.swiplistview;  
  2.   
  3. import java.util.List;  
  4.   
  5. import android.content.Context;  
  6. import android.view.LayoutInflater;  
  7. import android.view.View;  
  8. import android.view.View.OnClickListener;  
  9. import android.view.ViewGroup;  
  10. import android.widget.BaseAdapter;  
  11. import android.widget.Button;  
  12. import android.widget.TextView;  
  13.   
  14. import com.fortysevendeg.swipelistview.SwipeListView;  
  15.   
  16. public class DataAdapter extends BaseAdapter{  
  17.     private List<String> mDatas;    
  18.     private LayoutInflater mInflater;    
  19.     private SwipeListView mSwipeListView ;    
  20.     
  21.     public DataAdapter(Context context, List<String> datas , SwipeListView swipeListView)    
  22.     {    
  23.         this.mDatas = datas;    
  24.         mInflater = LayoutInflater.from(context);    
  25.         mSwipeListView = swipeListView;    
  26.     }    
  27.     
  28.     @Override    
  29.     public int getCount()    
  30.     {    
  31.         return mDatas.size();  
  32.           
  33.     }    
  34.     
  35.     @Override    
  36.     public Object getItem(int position)    
  37.     {    
  38.         return mDatas.get(position);    
  39.     }    
  40.     
  41.     @Override    
  42.     public long getItemId(int position)    
  43.     {    
  44.         return position;    
  45.     }    
  46.     
  47.     @Override    
  48.     public View getView(final int position, View convertView, ViewGroup parent)    
  49.     {    
  50.         convertView = mInflater.inflate(R.layout.item, null);    
  51.     
  52.         TextView tv = (TextView) convertView.findViewById(R.id.id_text);    
  53.         Button del = (Button) convertView.findViewById(R.id.id_remove);    
  54.         tv.setText(mDatas.get(position));    
  55.         del.setOnClickListener(new OnClickListener()    
  56.         {    
  57.             @Override    
  58.             public void onClick(View v)    
  59.             {    
  60.                 mDatas.remove(position);    
  61.                 notifyDataSetChanged();    
  62.                  /**  
  63.                   * 关闭SwipeListView  
  64.                   * 不关闭的话,刚删除位置的item存在问题 ,不能再次点击 
  65.                   */    
  66.                 mSwipeListView.closeOpenedItems();    
  67.             }    
  68.         });    
  69.             
  70.         return convertView;    
  71.     }    
  72. }  

最后是MainActivity的代码了,都比较简单:

[java]  view plain copy
  1. package com.example.swiplistview;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import android.app.Activity;  
  7. import android.os.Bundle;  
  8.   
  9. import com.fortysevendeg.swipelistview.BaseSwipeListViewListener;  
  10. import com.fortysevendeg.swipelistview.SwipeListView;  
  11.   
  12. public class MainActivity extends Activity {  
  13.     SwipeListView swipeListView;  
  14.     List<String> mDatas;  
  15.     DataAdapter adapter;  
  16.   
  17.     @Override  
  18.     protected void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.activity_main);  
  21.         mDatas = new ArrayList<String>();  
  22.         for (int i = 0; i < 20; i++) {  
  23.             mDatas.add("这是记录呢。。" + i);  
  24.         }  
  25.   
  26.         swipeListView = (SwipeListView) findViewById(R.id.example_lv_list);  
  27.         adapter = new DataAdapter(this, mDatas, swipeListView);  
  28.         swipeListView.setAdapter(adapter);  
  29.   
  30.         swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {  
  31.             // 这里可以重写很多方法  
  32.             @Override  
  33.             public void onListChanged() {  
  34.   
  35.                 super.onListChanged();  
  36.   
  37.             }  
  38.   
  39.             @Override  
  40.             public void onClickFrontView(int position) {  
  41.                   
  42.                 super.onClickFrontView(position);  
  43.                   
  44.             }  
  45.   
  46.         });  
  47.     }  
  48. }  

这样就大功告成了。

上面的都是最基本的功能,完成了上面的那些,然后我们就可以做相应的点击事件了。所以一起加油吧。

最后还有一个我在github下载的一个Demo,但并不是47deg的,是一个普通人写的,我给她上传了,下载地址http://download.csdn.net/detail/harryweasley/8190525

这里多说一下,你刚导入Eclipse时,会报一个不能解析android-14,你重启一下Eclipse,就好了。第二个问题,重启Eclipse后,bin文件里又有错误了,删除bin文件,Eclipse会重新自动生成一个,这样两个小bug就解决了。


4
 
0
我的同类文章
主题推荐
github  sdk  color  android  聊天  开源项目  文档  gradle
猜你在找
Qt基础与Qt on Android入门
Android底层技术:Java层系统服务(Android Service)
Android入门实战教程
3G Android实战开发从入门到精通
沈国阳解析美团推荐系统实战心得
fragment中嵌套viewpagervierpager中有多个fragment不显示
关于URL请求传递中文参数乱码
android中listView下有Button按钮始终在最底部
ViewPager实现真正的无限循环定时+手动
Android自定义图片+文字控件四种实现方法之 二--------个人最推荐的一种
查看评论
3楼  oaosj2015-09-29 16:16发表 [回复]
先收藏了。有时间看,这两天项目的事太忙-.-这是我之前一直琢磨的事情,自己想不出来又没在网上搜索办法,碰巧看到了。给博主一个赞-0-
2楼  小鱼20122015-02-11 14:21发表 [回复]
我想问一下如果我position = 0 时,这一条是不可滑动的,其他可以滑动 并删除,这个怎么设置?
Re:  HarryWeasley2015-02-11 17:41发表 [回复]
回复小鱼2012:我是这样想的,你既然不想让第一个item滑动,那你就完全可以将他弄出来啊,不需要共用一组数据的,因为你的第一个item的数据一直在,不会有改变
1楼  HarryWeasley2014-11-24 09:22发表 [回复] [引用] [举报]
http://download.csdn.net/detail/harryweasley/8190511这个是我自己的那个程序,就是上面那个效果图的小Demo,昨天不知道为什么上传后一直没显示,今天才显示出来
开启阅读模式

利用swipelistview完成qq聊天列表右滑删除功能

  2538人阅读  评论(4)  收藏  举报
  分类:

转载请注明出处:http://blog.csdn.net/harryweasley/article/details/41413547


前言:前段时间,由于自己比较悠闲,没有什么工作上的事情所做,所以当时就想,何不做一下qq聊天列表的item右滑出现后面的视图,然后我就开始着手自己做,之后无意间发现了可以利用一个github开源项目swiplistview完成,但是当我查看那些swiplistview的相关文档时,很不全面,github官网上下载的和之前他们写的文档已经有所不同,所以在这里我就重新来写一下怎么使用swiplistview的准备阶段。

之前的文档都是说,当从官网上下载下来后,有两个文件,一个是lib:android-swiplistview,另一个是例子:SwipListViewExampleActivity,但是现在下载后,解压后是这样的


显然已经和之前的不一样了,现在的官网上是用了gradle来构造Android程序,但我以前根本没有接触过gradle,所以只能自己去找以前的那个swiplistview。当时我也是纠结了很久,自己翻墙出去,各种Google,最后终于找到了,swiplistview,我之后会全部上传,共享给大家。

下面是qq的效果图:


下面是我这个项目的效果图:


现在我们进入正题:

我们一共需要两个jar包,一个swiplistview,如图所示:这三个下载地址http://download.csdn.net/detail/harryweasley/8190519


1. 引入android-swipelistview库:导入开源库,用Import选项,然后Android选项下的“Existing Android Code Into Workspace”引入库;在这里将“copy projects into workspace”前面打钩哦

2.引入android-swipelistview的依赖库nineoldandroids-2.4.0.jar:建立一个libs文件夹,将nineoldandroids-2.4.0.jar拷贝到libs文件夹之下;

3.引入android-swipelistview的依赖内部库android-support-v4.jar:项目的Android Tools选项,“Add Support Library”来增加android-support-v4库;(注:如果找不到对应的support库,可以通过SDK Manager来进行下载)
4.编译android-swipelistview库的jar包:项目的Properties选项,Android选项,勾选"Is Library";
5.编译android-swipelistview项目,在项目的bin目录应该能看到android-swipelistview.jar包。


这样,我们就完成了swiplistview的库了。

然后我们自己建立一个Android程序SwipListView进行测试,建好后,开始导入库,项目的Properties选项,Android选项,Library框选择add按钮添加swipelistview.jar包;

这里需要注意:swipelistview这个lib必须和SwiplistView在同一工作区间,否则导入的包前面会有红叉。如图所示



我们可以看下官网上关于SwipListView的描述

If you decide to use SwipeListView as a view, you can define it in your xml layout like this:

    <com.fortysevendeg.swipelistview.SwipeListView
            xmlns:swipe="http://schemas.android.com/apk/res-auto"
            android:id="@+id/example_lv_list"
            android:listSelector="#00000000"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            swipe:swipeFrontView="@+id/front"
            swipe:swipeBackView="@+id/back"
            swipe:swipeActionLeft="[reveal | dismiss]"
            swipe:swipeActionRight="[reveal | dismiss]"
            swipe:swipeMode="[none | both | right | left]"
            swipe:swipeCloseAllItemsWhenMoveList="[true | false]"
            swipe:swipeOpenOnLongPress="[true | false]"
            swipe:swipeAnimationTime="[miliseconds]"
            swipe:swipeOffsetLeft="[dimension]"
            swipe:swipeOffsetRight="[dimension]"
            />
  • swipeFrontView - Required - front view id. 即ListView Item正常显示的控件Id,且必须与Item的布局文件中的控件id一样
  • swipeBackView - Required - back view id.  手指滑动时显示的,隐藏在FrontView后面,且必须与item的布局文件中控件Id一样
  • swipeActionLeft - Optional - left swipe action Default: 'reveal'  左滑的动作,默认reveal,即显示BackView,还有dismiss,choice会触发响应的方法。
  • swipeActionRight - Optional - right swipe action Default: 'reveal' 同上
  • swipeMode - Gestures to enable or 'none'. Default: 'both' 设置左滑、右滑、都支持
  • swipeCloseAllItemsWhenMoveList - Close revealed items on list motion. Default: 'true' 当滚动listview时,关闭所有展开的Item,最好不要设置为false,由于item的复用,false存在一些问题。
  • swipeOpenOnLongPress - Reveal on long press Default: 'true' 长按时触发显示
  • swipeAnimationTime - item drop animation time. Default: android configuration 动画时间长度
  • swipeOffsetLeft - left offset 左偏移量
  • swipeOffsetRight - right offset 右偏移量
上面是基本属性,下面开始上代码:

首先是activity_main.xml下的代码:

[java]  view plain copy
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     tools:context=".MainActivity" >  
  6.   
  7.     <com.fortysevendeg.swipelistview.SwipeListView  
  8.         xmlns:swipe="http://schemas.android.com/apk/res-auto"  
  9.         android:id="@+id/example_lv_list"  
  10.         android:layout_width="fill_parent"  
  11.         android:layout_height="fill_parent"  
  12.         swipe:swipeActionLeft="reveal"  
  13.         swipe:swipeBackView="@+id/id_back"  
  14.         swipe:swipeCloseAllItemsWhenMoveList="true"  
  15.         swipe:swipeFrontView="@+id/id_front"  
  16.         swipe:swipeMode="left"  
  17.         swipe:swipeOffsetLeft="200dip"  
  18.         swipe:swipeOffsetRight="0dp"  
  19.         swipe:swipeOpenOnLongPress="true" />  
  20.   
  21. </RelativeLayout>  

接下来是itm.xml的代码:

[java]  view plain copy
  1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="60dp" >  
  5.   
  6.     <LinearLayout  
  7.         android:id="@+id/id_back"  
  8.         android:layout_width="match_parent"  
  9.         android:layout_height="match_parent"  
  10.         android:background="#ffcccccc"  
  11.         android:gravity="center|right" >  
  12.   
  13.         <Button  
  14.             android:id="@+id/id_remove"  
  15.             android:layout_width="60dp"  
  16.             android:layout_height="wrap_content"  
  17.             android:layout_gravity="center"  
  18.             android:layout_marginRight="4dp"  
  19.             android:background="@android:color/holo_green_light"  
  20.             android:text="Delete"  
  21.             android:textColor="#fff" >  
  22.         </Button>  
  23.     </LinearLayout>  
  24.   
  25.     <LinearLayout  
  26.         android:id="@+id/id_front"  
  27.         android:layout_width="match_parent"  
  28.         android:layout_height="match_parent"  
  29.         android:background="#ffffffff" >  
  30.   
  31.         <TextView  
  32.             android:id="@+id/id_text"  
  33.             android:layout_width="wrap_content"  
  34.             android:layout_height="wrap_content"  
  35.             android:layout_marginLeft="10dp"  
  36.             android:gravity="center_vertical"  
  37.             android:minHeight="?android:attr/listPreferredItemHeight"  
  38.             android:textAppearance="?android:attr/textAppearanceLarge"  
  39.             android:textColor="#000"  
  40.             android:textSize="25sp" >  
  41.         </TextView>  
  42.     </LinearLayout>  
  43.   
  44. </FrameLayout>  

这里要强调一下:对应布局的id和swipeListView中的frontView和backView的Id一致。

接下来是DataAdapter的代码

[java]  view plain copy
  1. package com.example.swiplistview;  
  2.   
  3. import java.util.List;  
  4.   
  5. import android.content.Context;  
  6. import android.view.LayoutInflater;  
  7. import android.view.View;  
  8. import android.view.View.OnClickListener;  
  9. import android.view.ViewGroup;  
  10. import android.widget.BaseAdapter;  
  11. import android.widget.Button;  
  12. import android.widget.TextView;  
  13.   
  14. import com.fortysevendeg.swipelistview.SwipeListView;  
  15.   
  16. public class DataAdapter extends BaseAdapter{  
  17.     private List<String> mDatas;    
  18.     private LayoutInflater mInflater;    
  19.     private SwipeListView mSwipeListView ;    
  20.     
  21.     public DataAdapter(Context context, List<String> datas , SwipeListView swipeListView)    
  22.     {    
  23.         this.mDatas = datas;    
  24.         mInflater = LayoutInflater.from(context);    
  25.         mSwipeListView = swipeListView;    
  26.     }    
  27.     
  28.     @Override    
  29.     public int getCount()    
  30.     {    
  31.         return mDatas.size();  
  32.           
  33.     }    
  34.     
  35.     @Override    
  36.     public Object getItem(int position)    
  37.     {    
  38.         return mDatas.get(position);    
  39.     }    
  40.     
  41.     @Override    
  42.     public long getItemId(int position)    
  43.     {    
  44.         return position;    
  45.     }    
  46.     
  47.     @Override    
  48.     public View getView(final int position, View convertView, ViewGroup parent)    
  49.     {    
  50.         convertView = mInflater.inflate(R.layout.item, null);    
  51.     
  52.         TextView tv = (TextView) convertView.findViewById(R.id.id_text);    
  53.         Button del = (Button) convertView.findViewById(R.id.id_remove);    
  54.         tv.setText(mDatas.get(position));    
  55.         del.setOnClickListener(new OnClickListener()    
  56.         {    
  57.             @Override    
  58.             public void onClick(View v)    
  59.             {    
  60.                 mDatas.remove(position);    
  61.                 notifyDataSetChanged();    
  62.                  /**  
  63.                   * 关闭SwipeListView  
  64.                   * 不关闭的话,刚删除位置的item存在问题 ,不能再次点击 
  65.                   */    
  66.                 mSwipeListView.closeOpenedItems();    
  67.             }    
  68.         });    
  69.             
  70.         return convertView;    
  71.     }    
  72. }  

最后是MainActivity的代码了,都比较简单:

[java]  view plain copy
  1. package com.example.swiplistview;  
  2.   
  3. import java.util.ArrayList;  
  4. import java.util.List;  
  5.   
  6. import android.app.Activity;  
  7. import android.os.Bundle;  
  8.   
  9. import com.fortysevendeg.swipelistview.BaseSwipeListViewListener;  
  10. import com.fortysevendeg.swipelistview.SwipeListView;  
  11.   
  12. public class MainActivity extends Activity {  
  13.     SwipeListView swipeListView;  
  14.     List<String> mDatas;  
  15.     DataAdapter adapter;  
  16.   
  17.     @Override  
  18.     protected void onCreate(Bundle savedInstanceState) {  
  19.         super.onCreate(savedInstanceState);  
  20.         setContentView(R.layout.activity_main);  
  21.         mDatas = new ArrayList<String>();  
  22.         for (int i = 0; i < 20; i++) {  
  23.             mDatas.add("这是记录呢。。" + i);  
  24.         }  
  25.   
  26.         swipeListView = (SwipeListView) findViewById(R.id.example_lv_list);  
  27.         adapter = new DataAdapter(this, mDatas, swipeListView);  
  28.         swipeListView.setAdapter(adapter);  
  29.   
  30.         swipeListView.setSwipeListViewListener(new BaseSwipeListViewListener() {  
  31.             // 这里可以重写很多方法  
  32.             @Override  
  33.             public void onListChanged() {  
  34.   
  35.                 super.onListChanged();  
  36.   
  37.             }  
  38.   
  39.             @Override  
  40.             public void onClickFrontView(int position) {  
  41.                   
  42.                 super.onClickFrontView(position);  
  43.                   
  44.             }  
  45.   
  46.         });  
  47.     }  
  48. }  

这样就大功告成了。

上面的都是最基本的功能,完成了上面的那些,然后我们就可以做相应的点击事件了。所以一起加油吧。

最后还有一个我在github下载的一个Demo,但并不是47deg的,是一个普通人写的,我给她上传了,下载地址http://download.csdn.net/detail/harryweasley/8190525

这里多说一下,你刚导入Eclipse时,会报一个不能解析android-14,你重启一下Eclipse,就好了。第二个问题,重启Eclipse后,bin文件里又有错误了,删除bin文件,Eclipse会重新自动生成一个,这样两个小bug就解决了。


4
 
0
我的同类文章
主题推荐
github  sdk  color  android  聊天  开源项目  文档  gradle
猜你在找
Qt基础与Qt on Android入门
Android底层技术:Java层系统服务(Android Service)
Android入门实战教程
3G Android实战开发从入门到精通
沈国阳解析美团推荐系统实战心得
查看评论
3楼  oaosj2015-09-29 16:16发表 [回复]
先收藏了。有时间看,这两天项目的事太忙-.-这是我之前一直琢磨的事情,自己想不出来又没在网上搜索办法,碰巧看到了。给博主一个赞-0-
2楼  小鱼20122015-02-11 14:21发表 [回复]
我想问一下如果我position = 0 时,这一条是不可滑动的,其他可以滑动 并删除,这个怎么设置?
Re:  HarryWeasley2015-02-11 17:41发表 [回复]
回复小鱼2012:我是这样想的,你既然不想让第一个item滑动,那你就完全可以将他弄出来啊,不需要共用一组数据的,因为你的第一个item的数据一直在,不会有改变
1楼  HarryWeasley2014-11-24 09:22发表 [回复] [引用] [举报]
http://download.csdn.net/detail/harryweasley/8190511这个是我自己的那个程序,就是上面那个效果图的小Demo,昨天不知道为什么上传后一直没显示,今天才显示出来
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值