Android QQ messages are left slide to delete instances (SwipeListViewEX for optimization) and androidswipelayout

Source: Internet
Author: User

Android QQ messages are left slide to delete instances (SwipeListViewEX for optimization) and androidswipelayout

Sliding left to delete an item message instance like a QQ message

Source code reference: http://blog.csdn.net/gaolei1201/article/details/42677951

I made some adjustments myself, all the code:

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

:

Only the following adapter classes are available:

  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 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.