android QQ消息左滑动删除实例(优化版SwipeListViewEX)_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > android QQ消息左滑动删除实例(优化版SwipeListViewEX)

android QQ消息左滑动删除实例(优化版SwipeListViewEX)

 2015/3/11 16:17:40  jenson138  程序员俱乐部  我要评论(0)
  • 摘要:仿QQ消息左滑动删除item消息实例源代码参考:http://blog.csdn.net/gaolei1201/article/details/42677951自己作了一些调整,全部代码下载地址:http://download.csdn.net/detail/jenson138/8490067效果图:以下只有适配器类:1packagecom.ryg.slideview;23importjava.util.List;45importcom.ryg.slideview.SwipeItemView
  • 标签:android view list 滑动 实例 优化 QQ

仿 QQ消息左滑动删除item消息实例

源代码参考:http://blog.csdn.net/gaolei1201/article/details/42677951

自己作了一些调整,全部代码下载地址:

http://download.csdn.net/detail/jenson138/8490067

效果图:

以下只有适配器类:

  1 package com.ryg.slideview;
  2 
  3 import java.util.List;
  4 
  5 import com.ryg.slideview.SwipeItemView.OnSlideListener;
  6 
  7 import android.content.Context;
  8 import android.view.LayoutInflater;
  9 import android.view.View;
 10 import android.view.View.OnClickListener;
 11 import android.view.ViewGroup;
 12 import android.widget.BaseAdapter;
 13 import android.widget.ImageView;
 14 import android.widget.TextView;
 15 import android.widget.Toast;
 16 
 17 
 18 public class HistoryListViewAdapter extends BaseAdapter {
 19 
 20     private LayoutInflater mInflater;
 21     private List<HistoryListItemObject> mMessageItems;
 22     private Context context;
 23     private SwipeItemView mLastSlideViewWithStatusOn;
 24     public HistoryListViewAdapter(Context context,List<HistoryListItemObject> mMessageItems) {
 25         mInflater = LayoutInflater.from(context);
 26         this.mMessageItems=mMessageItems;
 27         this.context=context;
 28     }
 29 
 30     @Override
 31     public int getCount() {
 32         return mMessageItems.size();
 33     }
 34 
 35     @Override
 36     public Object getItem(int position) {
 37         return mMessageItems.get(position);
 38     }
 39 
 40     @Override
 41     public long getItemId(int position) {
 42         return position;
 43     }
 44 
 45     @Override
 46     public View getView(final int position, View convertView, ViewGroup parent) {
 47         ViewHolder holder;
 48         SwipeItemView slideView = (SwipeItemView) convertView;
 49         if (slideView == null) {
 50             View itemView = mInflater.inflate(R.layout.history_listview_items, null);
 51 
 52             slideView = new SwipeItemView(context);
 53             slideView.setContentView(itemView);
 54 
 55             holder = new ViewHolder(slideView);
 56             slideView.setOnSlideListener(new OnSlideListener() {
 57                 
 58                 @Override
 59                 public void onSlide(View view, int status) {
 60                     // TODO Auto-generated method stub
 61                      if (mLastSlideViewWithStatusOn != null && mLastSlideViewWithStatusOn != view) {
 62                             mLastSlideViewWithStatusOn.shrink();
 63                         }
 64 
 65                         if (status == SLIDE_STATUS_ON) {
 66                             mLastSlideViewWithStatusOn = (SwipeItemView) view;
 67                         }
 68                 }
 69             });
 70             slideView.setTag(holder);
 71         } else {
 72             holder = (ViewHolder) slideView.getTag();
 73         }
 74         HistoryListItemObject item = mMessageItems.get(position);
 75 //        item.slideView = slideView;
 76         if(CustomSwipeListView.mFocusedItemView!=null){
 77         CustomSwipeListView.mFocusedItemView.shrink();
 78         }
 79 
 80         holder.icon.setImageResource(item.getIconRes());
 81         holder.title.setText(item.getTitle());
 82         holder.msg.setText(item.getMsg());
 83 //        holder.time.setText(item.time);
 84         holder.deleteHolder.setOnClickListener(new OnClickListener() {
 85             
 86             @Override
 87             public void onClick(View arg0) {
 88                 // TODO Auto-generated method stub
 89                 mMessageItems.remove(position);
 90                 Toast.makeText(context, String.valueOf(position), Toast.LENGTH_SHORT).show();
 91                 notifyDataSetChanged();
 92             }
 93         });
 94 
 95         return slideView;
 96     }
 97     private static class ViewHolder {
 98         public ImageView icon;
 99         public TextView title;
100         public TextView msg;
101 //        public TextView time;
102         public ViewGroup deleteHolder;
103 
104         ViewHolder(View view) {
105             icon = (ImageView) view.findViewById(R.id.icon);
106             title = (TextView) view.findViewById(R.id.title);
107             msg = (TextView) view.findViewById(R.id.msg);
108 //            time = (TextView) view.findViewById(R.id.time);
109             deleteHolder = (ViewGroup)view.findViewById(R.id.holder);
110         }
111     }
112 }

 

发表评论
用户名: 匿名