Mainactivity
Package Com.example.ss;import Java.util.arraylist;import Android.app.listactivity;import Android.graphics.drawable.colordrawable;import Android.os.bundle;import Android.util.log;import Android.view.motionevent;import Android.view.view;import Android.view.view.ontouchlistener;import Android.view.viewgroup;import Android.view.viewgroup.layoutparams;import Android.view.animation.animation;import Android.view.animation.animation.animationlistener;import Android.view.animation.animationutils;import Android.widget.adapterview;import Android.widget.button;import Android.widget.listview;import Android.widget.popupwindow;import Android.widget.popupwindow.ondismisslistener;import Android.widget.Toast; Import Com.example.ss.adapters.newslistadapter;import Com.example.ss.adapters.newslistadapter.viewholder;import Com.example.ss.adapters.user;public class Mainactivity extends Listactivity {private arraylist<user> array; Private Newslistadapter adapter;private Popupwindow pop; @Overridepublic voiD onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); final ListView listview = Getlistview (); Array = GetData (); adapter = new Newslistadapter (this, array); Listview.setadapter (adapter);//Create Popupwindowpop = new Popupwindow ();p op.settouchable (True);p op.setwidth (layoutparams.wrap_content);p op.setheight (layoutparams.wrap_ CONTENT);p op.setfocusable (true); Colordrawable DW = new colordrawable (0x00000000);p op.setbackgrounddrawable (DW);//This method is: Left slide when delete button, click other Location, delete button disappears, Return to normal state pop.setondismisslistener (new Ondismisslistener () {@Overridepublic void Ondismiss () {UnDelete (CurrentView,-2);}); * * Add ListView slider to listen */listview.setontouchlistener (new Ontouchlistener () {float x, y, UPX, Upy;public boolean OnTouch (View View, Motionevent event) {if (event.getaction () = = Motionevent.action_down) {x = Event.getx (); y = Event.gety ();} if (event.getaction () = = motionevent.action_up) {UPX = Event.getx (); upy = Event.gety (); int position1 = ((ListView) view). P Ointtoposition ((int) x, (int) y); int positIon2 = (ListView) View. Pointtoposition (() upx, (int) upy), if (Position1 = = position2) {View V = (ListView) view). Get Childat (Position1); if ((X-UPX) > 0) {/** * finger swipe left, popup delete button, item appears animated */preparedelete (V, Position1);}} }return false;}}); * * ListView Item Click event *///++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Listview.setonitemclicklistener (New Adapterview.onitemclicklistener () {@Overridepublic void Onitemclick ( Adapterview<?> parent, View rowview,int Positon, long id) {if (CurrentView! = null) {UnDelete (CurrentView, positon); }}});} protected void UnDelete (final View rowview, final int positon) {if (rowview==null) {return;} if ("Half_delete". Equals (((Viewholder) Rowview.gettag ()). Status) {final Animation Animation = (Animation) Animationutils.loadanimation (Rowview.getcontext (), r.anim.item2); Animation.setfillafter (true);((ViewHolder) Rowview.gettag ()). Status = "Normal"; CurrentView = Null;animation.setanimationlistener (new Animationlistener () {public voiD Onanimationstart (Animation Animation) {}public void onanimationrepeat (Animation Animation) {}public void Onanimationend (Animation Animation) {rowview.clearanimation ();}}); Rowview.startanimation (animation);}} ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++private View currentview;protected Void Preparedelete (Final View rowview, final int positon) {//If not in delete state if (! " Half_delete ". Equals (((Viewholder) Rowview.gettag ()). Status) {final Animation Animation = (Animation) Animationutils.loadanimation (Rowview.getcontext (), R.anim.item); Animation.setfillafter (true);((ViewHolder) Rowview.gettag ()). Status = "Half_delete";//Assign to member variable CurrentView = rowview;//Add Delete button Popupadddeletebutton (Rowview, Positon); rowview.startanimation (animation);}} private void Adddeletebutton (final view view, final int position) {button Button = new Button (mainactivity.this); button.se Ttext ("delete"), Button.setvisibility (view.visible);p op.setcontentview (button);p Op.showasdropdown (View, 560,-130); Button.setonclickListener (New View.onclicklistener () {@Overridepublic void OnClick (view v) {//Click the Delete button to delete the Operation Dodelete (view, position); Pop.dismiss (); CurrentView = null;}});} protected void DoDelete (final View rowview, final int positon) {if (Rowview = = null) {return;} if ("Half_delete". Equals (((Viewholder) Rowview.gettag ()). Status) {final Animation Animation = (Animation) Animationutils.loadanimation (Rowview.getcontext (), r.anim.item2); animation.setduration (0); Animation.setfillafter (True);((Viewholder) Rowview.gettag ()). Status = "Normal"; CurrentView = Null;animation.setanimationlistener (new Animationlistener () {public void Onanimationstart (animation Animation) {}public void Onanimationrepeat (animation animation) {}public void Onanimationend (animation animation) { Rowview.clearanimation (); Array.remove (positon); adapter.notifydatasetchanged ();}); Rowview.startanimation (animation);}} Private arraylist<user> GetData () {arraylist<user> users = new arraylist<user> (); User user = new user (); user.logo = "http://t10.baidu.com/it/u=3485469777,1638135480&fm=56"; user.name = "1111"; user.time = "11:11"; user.sign = " Xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx "; users.add (user); user = new User (); user.name =" 222222 "; users.add (user); user = new User (); user.name = "3333"; users.add (user); user = new User (); user.name = "44444"; users.add (user); user = new User (); User.Name = "5555"; users.add (user); user = new User (); user.name = "6666"; users.add (user); user = new User (); user.name = "777 Users.add (user), user = new User (), User.Name = "88888"; users.add (user); user = new User (); user.name = "99999"; Users.add (user), user = new User (), User.Name = "AAAAA"; users.add (user); return users;}}
Newslistadapter
Package Com.example.ss.adapters;import Java.util.list;import Android.content.context;import Android.graphics.drawable.drawable;import Android.view.layoutinflater;import Android.view.View;import Android.view.viewgroup;import Android.widget.baseadapter;import Android.widget.imageview;import Android.widget.textview;import com.example.ss.r;/** * Created by xch on 2014/6/14. */public class Newslistadapter extends Baseadapter {private Context mcontext; Private list<user> musers; Drawable defaultdrawable; Public Newslistadapter (context context, list<user> users) {this.mcontext = context; This.musers = users; defaultdrawable = Mcontext.getresources (). getdrawable (R.drawable.ic_launcher); } @Override public int getcount () {return musers.size (); } @Override public Object getItem (int position) {return musers.get (position); } @Override public long getitemid (int position) {return position; } @OverRide public view GetView (int position, view Convertview, ViewGroup parent) {view view = null; Final Viewholder Holder; if (Convertview = = null) {view = Layoutinflater.from (Mcontext). Inflate (R.layout.item_new, NULL); Holder = new Viewholder (); Holder.headimage = (ImageView) View.findviewbyid (R.id.new_it_iv_head); Holder.nametext = (TextView) View.findviewbyid (r.id.new_it_tv_name); Holder.signtext = (TextView) View.findviewbyid (r.id.new_it_tv_sign); Holder.timetext = (TextView) View.findviewbyid (r.id.new_it_tv_time); View.settag (holder); } else {view = Convertview; Holder = (viewholder) view.gettag (); } User user = Musers.get (position); Holder.headImage.setImageDrawable (defaultdrawable); Holder.nameText.setText (User.Name); Holder.signText.setText (user.sign); Holder.timeText.setText (User.time); return view; } public class Viewholder {ImageView headimage; TextView Nametext; TextView Signtext; TextView timetext; public String status; }}
User
Package Com.example.ss.adapters;public class User {public long uid;public string Name;public string Logo;public string Tim E;public String sign;}
Item_new.xml
<?xml version= "1.0" encoding= "Utf-8"? ><framelayout xmlns:android= "http://schemas.android.com/apk/res/ Android "Android:layout_width=" Match_parent "android:layout_height=" 60DP "> <relativelayout android: Id= "@+id/new_it_rl" android:layout_width= "match_parent" android:layout_height= "60DP" > <imagevi EW android:id= "@+id/new_it_iv_head" android:layout_width= "50DP" android:layout_height= "50 DP "android:layout_alignparentleft=" true "android:layout_alignparentstart=" true "Android: Layout_alignparenttop= "true" android:layout_margin= "5DP" android:src= "@drawable/ic_launcher"/> <textview android:id= "@+id/new_it_tv_name" android:layout_width= "Wrap_content" a ndroid:layout_height= "Wrap_content" android:layout_alignparenttop= "true" android:layout_margintop= "1 0DP "Android:layout_torightof= "@+id/new_it_iv_head" android:text= "new text" android:textsize= "16sp"/> <textview Android:id= "@+id/new_it_tv_sign" android:layout_width= "Wrap_content" Android:layout_heig ht= "Wrap_content" android:layout_alignbottom= "@+id/new_it_iv_head" android:layout_marginbottom= "5DP" android:layout_torightof= "@+id/new_it_iv_head" android:text= "new text"/> <textview Android:id= "@+id/new_it_tv_time" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content" android:layout_alignparentend= "true" android:layout_alignparentright= "true" android:layout_aligntop= "@+id/new_it_tv_name" android:layout_marginright= "130DP" android:text= "new Text "/> </RelativeLayout></FrameLayout>
Item.xml
<?xml version= "1.0" encoding= "Utf-8"? ><translate xmlns:android= "http://schemas.android.com/apk/res/ Android " android:duration=" android:fromxdelta= " 0%" android:fromydelta= "0" android: Toxdelta= " -30%p" android:toydelta= "0"/>
Item2.xml
<?xml version= "1.0" encoding= "Utf-8"? ><translate xmlns:android= "http://schemas.android.com/apk/res/ Android " android:duration=" android:fromxdelta= " -30%p" android:fromydelta= "0" android: Toxdelta= "0" android:toydelta= "0"/>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Slide-Slip Removal Advanced (ii)