Question

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;
Was it helpful?

Solution

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.").

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top