Android:刷卡列表项导致clickOnItem

Android:刷卡列表项导致clickOnItem,第1张

概述我想将listview的项目向右和向左滑动.为此我使用这个项目.https://github.com/daimajia/AndroidSwipeLayout我可以刷物品,但是当我刷完物品后,物品的onclick被召唤.我不想要这个. 我在SwipeListener上做了很多努力,但是我并没有完全克服这种情况.我可以在不调用onClickItem的情

我想将ListvIEw的项目向右和向左滑动.
为此我使用这个项目.

https://github.com/daimajia/AndroidSwipeLayout
我可以刷物品,但是当我刷完物品后,物品的onclick被召唤.我不想要这个.
 我在SwipeListener上做了很多努力,但是我并没有完全克服这种情况.我可以在不调用onClickItem的情况下从左向右滑动,但是当我向后滑动itemClick调用时

swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {            @OverrIDe            public voID onStartopen(SwipeLayout swipeLayout) {                lineIsClose = false;            }            @OverrIDe            public voID onopen(SwipeLayout swipeLayout) {                lineIsClose = false;            }            @OverrIDe            public voID onStartClose(SwipeLayout swipeLayout) {                lineIsClose = false;            }            @OverrIDe            public voID onClose(SwipeLayout swipeLayout) {                lineIsClose  = true ;            }            @OverrIDe            public voID onUpdate(SwipeLayout swipeLayout, int i, int i1) {            }            @OverrIDe            public voID onHandRelease(SwipeLayout swipeLayout, float v, float v1) {            }        });

编辑:一些代码

adapter = new Productslistadapter(getActivity(), currentList);            adapter.setMode(Attributes.Mode.Multiple);            ListVIEw.setAdapter(adapter); 
package com.akakce.market.Adapters;import androID.content.Context;import androID.graphics.color;import androID.graphics.Paint;import androID.os.Handler;import androID.vIEw.LayoutInflater;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.ImageVIEw;import androID.Widget.TextVIEw;import com.daimajia.swipe.SwipeLayout;import com.daimajia.swipe.adapters.BaseSwipeAdapter;import com.akakce.market.Models.ProductList;import com.akakce.market.Managers.SharedPrefManager;import com.akakce.market.Models.Product;import com.akakce.market.R;import com.akakce.market.Utils.GifMovIEVIEw;import java.util.List;/** * Created by cuneyt on 1.7.2015. */public class Productslistadapter extends BaseSwipeAdapter {    Context mContext;    List<Product> List;    ProductList currentList;    boolean lineIsClose = true;    public Productslistadapter(Context context, ProductList currentList) {        this.mContext = context;        this.currentList = currentList;        this.List = currentList.getProducts();    }    @OverrIDe    public int getSwipeLayoutResourceID(int i) {        return R.ID.swipe;    }    @OverrIDe    public VIEw generateVIEw(final int position, VIEwGroup vIEwGroup) {        VIEw v = LayoutInflater.from(mContext).inflate(R.layout.item_products_List, null);        return v;    }    @OverrIDe    public voID fillValues(final int position, VIEw convertVIEw) {        Product temp = List.get(position);        final TextVIEw name = (TextVIEw) convertVIEw.findVIEwByID(R.ID.name);        final TextVIEw count = (TextVIEw) convertVIEw.findVIEwByID(R.ID.count);        final ImageVIEw categoryVIEw = (ImageVIEw) convertVIEw.findVIEwByID(R.ID.imageVIEw_category);        final GifMovIEVIEw gifMovIEVIEw = (GifMovIEVIEw) convertVIEw.findVIEwByID(R.ID.gif_1);        final SwipeLayout swipeLayout = (SwipeLayout) convertVIEw.findVIEwByID(getSwipeLayoutResourceID(position));        swipeLayout.getDragEdgeMap().clear();        swipeLayout.addDrag(SwipeLayout.DragEdge.left, swipeLayout.findVIEwByID(R.ID.bottom_wrapper));        swipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {            @OverrIDe            public voID onStartopen(SwipeLayout swipeLayout) {                lineIsClose = false;            }            @OverrIDe            public voID onopen(SwipeLayout swipeLayout) {                lineIsClose = false;            }            @OverrIDe            public voID onStartClose(SwipeLayout swipeLayout) {                lineIsClose = false;            }            @OverrIDe            public voID onClose(SwipeLayout swipeLayout) {                lineIsClose  = true ;            }            @OverrIDe            public voID onUpdate(SwipeLayout swipeLayout, int i, int i1) {            }            @OverrIDe            public voID onHandRelease(SwipeLayout swipeLayout, float v, float v1) {            }        });        if (temp.isCompleted()) {            name.setTextcolor(mContext.getResources().getcolor(R.color.gray));            name.setPaintFlags(name.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);            count.setPaintFlags(count.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);        } else {            name.setTextcolor(mContext.getResources().getcolor(R.color.black));            name.setPaintFlags(name.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));            count.setPaintFlags(count.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));        }        name.setText(temp.getname());        count.setText("" + temp.getCount());        if (position % 2 == 0)// oylesine var            categoryVIEw.setBackgroundcolor(color.BLUE);        if (position % 3 == 0)            categoryVIEw.setBackgroundcolor(color.RED);        convertVIEw.setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw v) {                if ( lineIsClose ){                    gifMovIEVIEw.setVisibility(VIEw.VISIBLE);                final Handler handler = new Handler();                handler.postDelayed(new Runnable() {                    @OverrIDe                    public voID run() {                        gifMovIEVIEw.setVisibility(VIEw.GONE);                        if (!List.get(position).isCompleted()) {//false ise true yap                            List.get(position).setCompleted(true);                            name.setTextcolor(mContext.getResources().getcolor(R.color.gray));                            name.setPaintFlags(name.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);                            count.setPaintFlags(count.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);                        } else { // true ise false yap                            List.get(position).setCompleted(false);                            name.setTextcolor(mContext.getResources().getcolor(R.color.black));                            name.setPaintFlags(name.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));                            count.setPaintFlags(count.getPaintFlags() & (~Paint.STRIKE_THRU_TEXT_FLAG));                        }                        currentList.setProducts(List);                        SharedPrefManager.saveList(currentList);                    }                }, 600);                //saveList(gifMovIEVIEw);            }        }    });        convertVIEw.findVIEwByID(R.ID.bottom_wrapper).setonClickListener(new VIEw.OnClickListener() {            @OverrIDe            public voID onClick(VIEw vIEw) {                swipeLayout.close();                //                // removeFromList(position);                List.remove(position);                notifyDataSetChanged();            }        });    }    @OverrIDe    public int getCount() {        return List.size();    }    @OverrIDe    public Object getItem(int position) {        return List.get(position);    }    @OverrIDe    public long getItemID(int position) {        return position;    }}

解决方法:

我有同样的问题,我通过这段代码解决了这个问题:

vIEwHolder.swipeLayout.addSwipeListener(new SimpleSwipeListener() {        @OverrIDe        public voID onopen(SwipeLayout layout) {            super.onopen(layout);           ((Fragment)mFragment).setListVIEwClickable(false);        }        @OverrIDe        public voID onClose(SwipeLayout layout) {            super.onClose(layout);            mHandler.postDelayed(new Runnable() {                @OverrIDe                public voID run() {                    ((Fragment) mFragment).setListVIEwClickable(true);                }            } , 100);        }        @OverrIDe        public voID onStartopen(SwipeLayout layout) {            ((Fragment)mFragment).setListVIEwClickable(false);            super.onStartopen(layout);          }        @OverrIDe        public voID onStartClose(SwipeLayout layout) {            ((Fragment)mFragment).setListVIEwClickable(false);            super.onStartClose(layout);        }    });

通常当滑动布局打开时,我禁用ListvIEw单击,当滑动布局关闭时,启用ListvIEw单击一段时间后,如100 ms.

总结

以上是内存溢出为你收集整理的Android:刷卡列表导致clickOnItem全部内容,希望文章能够帮你解决Android:刷卡列表项导致clickOnItem所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1114983.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存