Check your imports, make sure you are importing the correct OnLongClickListener.
The method setOnLongClickListener(View.OnLongClickListener) in the type View is not applicable for the arguments (new OnLongClickListener(){})
-
01-07-2022 - |
Вопрос
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.
Решение
Другие советы
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;
}
});
Не связан с StackOverflow