You are not setting the onLongClickListener
for someText
. You need to add this:
someText.setOnLongClickListener(this);
This line will attach the listener object to the TextView
Object. In the first case, you make the call to setOnLongClickListener
, which is why it works. In this instance, you are creating a new onLongClickListener
object in-line.
In the second example, your Activity
is inheriting OnLongClickListener
, which makes it an instance of that object. So to set the listener for someText
, pass the listener this
, which is a reference to the current class.