ImageButton onlongpress causes onclick as well

回眸只為那壹抹淺笑 提交于 2019-12-25 04:17:32

问题


i have an application with an imagebutton that has both an onclick and an onlongclick listener. However, when the button is long pressed, both of these listeners are executing. Any suggestions?

d1.setOnLongClickListener(new OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            selectMode = true;
            dockNum = 1;
            sd1.open();
            d1.cancelLongPress();
            return false;
        }

    });

...d1.setOnClickListener(this);

...case R.id.d1:
        if(d1s.equals("empty")) {
            selectMode = true;
            dockNum = 1;
            sd1.open();
        } else {
            Intent d1i = pm.getLaunchIntentForPackage(d1s);
            startActivity(d1i);
        }
    break;

回答1:


I think your problem has to do with the fact that you're returning false in your onLongClick method. Try returning true instead (despite the fact that you're canceling the long click, returning true is just saying "I've handled this, no further action is required.").



来源:https://stackoverflow.com/questions/7940357/imagebutton-onlongpress-causes-onclick-as-well

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!