xamarin - Click an Item -hold- and swipe to an other site -
if object clicked, next page should not called immediately. click should remain on object until scroll through wipe next page.
how can hold click command on item?
how can swipe clicked item other page?
update
got hold , swipe now, need similar .gif:
click 1 item > onhold> swipe holded item left , right.
this actual behavior:
public class touchadapter : baseadapter<einsatzdatamodel>, view.iontouchlistener { private list<einsatzdatamodel> items = new list<einsatzdatamodel>(); private activity context; private int index = -1; public enum swipeaction { lr, // left right rl, // right left tb, // top bottom bt, // bottom top none // when no action detected } private int min_distance = 100; private float downx, downy, upx, upy; private swipeaction maction = swipeaction.none; private string ein_gridlayout; public touchadapter(activity context, list<einsatzdatamodel> items) : base() { this.context = context; this.items = items; } public override einsatzdatamodel this[int position] { { return items[position]; } } public override int count { { return items.count; } } public override long getitemid(int position) { return position; } private void setselecteditem(int position) { index = position; notifydatasetchanged(); } private class myviewholder : java.lang.object { public gridlayout ein_gridlayout { get; set; } //public textview description { get; set; } public int index { get; set; } } public override view getview(int position, view convertview, viewgroup parent) { myviewholder holder = null; var view = convertview; if (view != null) holder = view.tag myviewholder; if (holder == null) { holder = new myviewholder(); view = context.layoutinflater.inflate(resource.layout.einsatzlvrow, null); holder.ein_gridlayout = view.findviewbyid<gridlayout>(resource.id.details); //holder.description = view.findviewbyid<textview>(resource.id.detailtxt); holder.index = position; view.tag = holder; } ein_gridlayout = items[position].details; //holder.description.text = items[position].description; if (index != -1 && position == index) { holder.ein_gridlayout.setbackgroundcolor(android.graphics.color.red); //holder.description.setbackgroundcolor(android.graphics.color.pink); } else { holder.ein_gridlayout.setbackgroundcolor(android.graphics.color.royalblue); //holder.description.setbackgroundcolor(android.graphics.color.seagreen); } view.setontouchlistener(this); return view; } public bool ontouch(view v, motionevent e) { switch (e.action) { case motioneventactions.down: downx = e.getx(); downy = e.gety(); maction = swipeaction.none; break; case motioneventactions.move: upx = e.getx(); upy = e.gety(); var deltax = downx - upx; var deltay = downy - upy; if (math.abs(deltax) > min_distance) { if (deltax < 0) { maction = swipeaction.lr; } else if (deltax > 0) { maction = swipeaction.rl; } return true; } else if (math.abs(deltay) > min_distance) { if (deltay < 0) { maction = swipeaction.tb; } else if (deltay > 0) { maction = swipeaction.bt; } return false; } break; case motioneventactions.up: var holder = v.tag myviewholder; if (maction == swipeaction.none) { setselecteditem(holder.index); } else if (maction == swipeaction.lr | maction == swipeaction.rl) { if (holder.index == index) context.startactivity(typeof(detailmain)); } break; } return true; } }
to highlight item when clicked, can set background color item's view, perform swipe gesture each item, think need implement iontouchlistener
each item. here created adapter implement feature:
public class lvadapter : baseadapter<listitemmodel>, view.iontouchlistener { private list<listitemmodel> items = new list<listitemmodel>(); private activity context; private int index = -1; public enum swipeaction { lr, // left right rl, // right left tb, // top bottom bt, // bottom top none // when no action detected } private int min_distance = 100; private float downx, downy, upx, upy; private swipeaction maction = swipeaction.none; public lvadapter(activity context, list<listitemmodel> items) : base() { this.context = context; this.items = items; } public override listitemmodel this[int position] { { return items[position]; } } public override int count { { return items.count; } } public override long getitemid(int position) { return position; } private void setselecteditem(int position) { index = position; notifydatasetchanged(); } private class myviewholder : java.lang.object { public textview name { get; set; } public textview description { get; set; } public int index { get; set; } } public override view getview(int position, view convertview, viewgroup parent) { myviewholder holder = null; var view = convertview; if (view != null) holder = view.tag myviewholder; if (holder == null) { holder = new myviewholder(); view = context.layoutinflater.inflate(resource.layout.itemcell, null); holder.name = view.findviewbyid<textview>(resource.id.nametxt); holder.description = view.findviewbyid<textview>(resource.id.detailtxt); holder.index = position; view.tag = holder; } holder.name.text = items[position].name; holder.description.text = items[position].description; if (index != -1 && position == index) { holder.name.setbackgroundcolor(android.graphics.color.red); holder.description.setbackgroundcolor(android.graphics.color.pink); } else { holder.name.setbackgroundcolor(android.graphics.color.royalblue); holder.description.setbackgroundcolor(android.graphics.color.seagreen); } view.setontouchlistener(this); return view; } public bool ontouch(view v, motionevent e) { switch (e.action) { case motioneventactions.down: downx = e.getx(); downy = e.gety(); maction = swipeaction.none; break; case motioneventactions.move: upx = e.getx(); upy = e.gety(); var deltax = downx - upx; var deltay = downy - upy; if (math.abs(deltax) > min_distance) { if (deltax < 0) { maction = swipeaction.lr; } else if (deltax > 0) { maction = swipeaction.rl; } return true; } else if (math.abs(deltay) > min_distance) { if (deltay < 0) { maction = swipeaction.tb; } else if (deltay > 0) { maction = swipeaction.bt; } return false; } break; case motioneventactions.up: var holder = v.tag myviewholder; if (maction == swipeaction.none) { setselecteditem(holder.index); } else if (maction == swipeaction.lr | maction == swipeaction.rl) { if (holder.index == index) context.startactivity(typeof(activity1)); } break; } return true; } }
the listitemmodel
quite simple side:
public class listitemmodel { public string name { get; set; } public string description { get; set; } }
you can try modify model , holder need.
Comments
Post a Comment