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