I'm trying to make my view accept long clicks, but nothing happens.
I looked at other similar posts but found no solution.
Any idea what might be happening?
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<com.examples.danilofernandes.housemap.ViewForLayout
android:id="@+id/layout"
android:layout_width="100px"
android:layout_height="100px" />
<Button
android:id="@+id/button"
android:text="hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/layout"/>
</RelativeLayout>
The class:
public class ViewForLayout extends View {
...
public ViewForLayout(final Context context, AttributeSet attrs) {
super(context, attrs);
setLongClickable(true);
setOnLongClickListener(new MyLongClickListenerClass());
....
}
public class MyLongClickListenerClass implements OnLongClickListener{
@Override
public boolean onLongClick(View v) {
Toast.makeText(context, "I'm in", Toast.LENGTH_SHORT).show();
return true;
}
}
}