Swipelistview How to use

Source: Internet
Author: User

The Swipelistview XML looks like this:

<com.fortysevendeg.swipelistview.swipelistview
Android:id= "@+id/swipe_lv"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
Android:listselector= "#ff0000"
App:swipeactionleft= "Reveal"
App:swipeactionright= "Reveal"
App:swipeanimationtime= "0"
app:swipebackview= "@+id/back"//This ID needs to match the back ID of item (front)
App:swipecloseallitemswhenmovelist= "true"///Drag the ListView to close the pulled item (some suggest true, otherwise there may be a problem)
app:swipefrontview= "@+id/front"
App:swipemode= "Both"//whether or not all can pull
app:swipeoffsetleft= "0DP"//Pull Distance
app:swipeoffsetright= "0DP"
App:swipeopenonlongpress= "false"//long press to open item
/>

Set Adapter:

public class Swipeadapter extends Arrayadapter<string> {
Private Layoutinflater Minflater;
Private list<string> objects;
Private Swipelistview Mswipelistview;
Public Swipeadapter (context context, int textviewresourceid,list<string> objects, Swipelistview mswipelistview) {
Super (context, Textviewresourceid, objects);
This.objects = objects;
This.mswipelistview = Mswipelistview;
Minflater = (layoutinflater) context.getsystemservice (Context.layout_inflater_service);
}

@Override
Public View GetView (final int position, View Convertview, ViewGroup parent) {
Viewholder holder = null;
if (Convertview = = null) {
Convertview = Minflater.inflate (R.layout.package_row, parent, false);
Holder = new Viewholder ();
Holder.mfronttext = (TextView) Convertview.findviewbyid (r.id.example_row_tv_title);
Holder.mbackedit = (Button) Convertview.findviewbyid (r.id.example_row_b_action_3);
Holder.mbackdelete = (Button) Convertview.findviewbyid (r.id.example_row_b_action_2);
Convertview.settag (holder);
}else{
Holder = (viewholder) convertview.gettag ();
}
Holder.mBackDelete.setOnClickListener (New Onclicklistener () {
@Override
public void OnClick (View v) {
Mswipelistview.closeanimate (position);
Mswipelistview.dismiss (position);
}
});
String item = getItem (position);
Holder.mFrontText.setText (item);
return convertview;
}
Class viewholder{
TextView Mfronttext;
Button Mbackedit,mbackdelete;
}
}

Set Listener:

Class Testswipelistviewlistener extends Baseswipelistviewlistener {
@Override
public void Onclickfrontview (int position) {
TODO auto-generated Method Stub
Super.onclickfrontview (position);
Toast.maketext (Getapplicationcontext (), "click:" +testdata.get (position), Toast.length_short). Show ();
}
@Override
public void Ondismiss (int[] reversesortedpositions) {
for (int position:reversesortedpositions) {
The toast that pops up here must be in front, or it will show the next item
Toast.maketext (Getapplicationcontext (), "Remove:" +testdata.get (position), Toast.length_short). Show ();
Testdata.remove (position);
}
Adapter.notifydatasetchanged ();
}
}

Swipelistview How to use

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.