Android ListView Pull to refresh and Swipe List item to reveal buttons -
i working on android listview. implemented pull refresh through xlistview, want implement swipe left right show buttons list item on listview. how can it? or how add 2 libs same on listview.
my listview in xml is.
<com.orderlyexpo.www.listview.refresh.xlistview android:id="@+id/lvorders" android:layout_width="match_parent" android:layout_height="wrap_content" android:divider="@color/gray_text" android:dividerheight="@dimen/dp1x" />
don't use lib swipe, make own view , can use pull refresh same lib.
just way.
add class name.
swipedetector.java
public class swipedetector implements view.ontouchlistener { public static enum action { lr, // left right rl, // right left tb, // top bottom bt, // bottom top none // when no action detected } private static final string logtag = "swipedetector"; private static final int min_distance = 100; private float downx, downy, upx, upy; private action mswipedetected = action.none; public boolean swipedetected() { return mswipedetected != action.none; } public action getaction() { return mswipedetected; } public boolean ontouch(view v, motionevent event) { switch (event.getaction()) { case motionevent.action_down: { downx = event.getx(); downy = event.gety(); mswipedetected = action.none; return false; // allow other events click processed } case motionevent.action_move: { upx = event.getx(); upy = event.gety(); float deltax = downx - upx; float deltay = downy - upy; // horizontal swipe detection if (math.abs(deltax) > min_distance) { // left or right if (deltax < 0) { // logger.show(log.info,logtag, "swipe left right"); mswipedetected = action.lr; return true; } if (deltax > 0) { // logger.show(log.info,logtag, "swipe right left"); mswipedetected = action.rl; return true; } } else // vertical swipe detection if (math.abs(deltay) > min_distance) { // top or down if (deltay < 0) { // logger.show(log.info,logtag, "swipe top bottom"); mswipedetected = action.tb; return false; } if (deltay > 0) { // logger.show(log.info,logtag, "swipe bottom top"); mswipedetected = action.bt; return false; } } return true; } } return false; } }
and call listview or item onclicklistner mathod. called itemclick baseadapter.
convertview.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub if(swipedetector.swipedetected()) { if(swipedetector.getaction() == action.lr) { viewholder.chatbutton.setvisibility(view.visible); //outterlayout relativelayout.layoutparams relativeparams = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content); relativeparams.addrule(relativelayout.right_of, viewholder.chatbutton.getid()); relativeparams.setmargins(20, 0, 0, 0); viewholder.outterlayout.setlayoutparams(relativeparams); viewholder.tvdeliver.setvisibility(view.gone); return; } else { viewholder.chatbutton.setvisibility(view.gone); relativelayout.layoutparams relativeparams = new relativelayout.layoutparams(relativelayout.layoutparams.wrap_content, relativelayout.layoutparams.wrap_content); relativeparams.setmargins(0, 0, 0, 0); viewholder.outterlayout.setlayoutparams(relativeparams); return; } } toast.maketext(context, "click", 2000).show(); } });
Comments
Post a Comment