0
I’m trying to get my view to accept long clicks, but nothing happens.
I looked at other similar posts but found no solution.
Any idea what might be going on?
<?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;
}
}
}
returns false..
– Lollipop
And use
Log.v("onLongClick", "Foi clicado");
– Lollipop
I tried. Unsuccessfully...
– user2929914
Tried to put something here:
ALGUMA_VIEW.setOnLongClickListener(new MyLongClickListenerClass());
– Lollipop
For example:
btn = (Button) findViewById(R.id.button1);
 btn.setOnClickListener(this);
 btn.setOnLongClickListenersetOnLongClickListener(new MyLongClickListenerClass());;
– Lollipop
setLongClickable(true);
Why settrue
before clicking?– Lollipop
When I think of this kind of problem I always debug and see if the method is being called,
ViewForLayout
is being executed?– Skywalker
try tbm this
Toast.makeText(v.getContext(), "I'm in", Toast.LENGTH_SHORT).show();
– Skywalker