The method setOnLongClickListener(View.OnLongClickListener) in the type View is not applicable for the arguments (new OnLongClickListener(){})

StackOverflow https://stackoverflow.com/questions/19538991

سؤال

I have an ImageView that I want to respond to a long-press.

I have implemented this very method in another application without any issues but I just copied and pasted the code into another application and it's giving me the following syntax error:

The method setOnLongClickListener(View.OnLongClickListener) in the type View is not applicable for the arguments (new OnLongClickListener(){})

The code block is:

imageView.setOnLongClickListener(new OnLongClickListener() {
    public boolean onLongClick(View arg0) {
        // do something here
        return true;                         
    }
});

This view method is available since API level 1 so I am not sure what I am doing wrong.

هل كانت مفيدة؟

المحلول

Check your imports, make sure you are importing the correct OnLongClickListener.

نصائح أخرى

Two imports are needed

import android.view.View.OnLongClickListener;
import android.widget.ImageButton;

Change a OnLongClickListener to full path to android.View.OnLongClickListener

 imageView.setOnLongClickListener(new android.View.OnLongClickListener() {
        public boolean onLongClick(View arg0) {
            // do something here
            return true;                         
        }
    });
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top