Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Basically the answer is: Your view is not receiving touch events, because it's not in views hierarchy, so click callback is also not called. Actually, view should be in View hierarchy (in other words, added to some upper level view and finally, to the window) in order to participate is user interactions.<br/> So, if You want to implement somthing covering Your view, then it should be ViewGroup or shouldn't be related to view at all and be some abstract container.<br/> E.g. using the way below click works without any issues (but You will need second view or modify BallView to draw bmp): DrawView:</p> <pre><code>public class DrawView extends FrameLayout implements View.OnClickListener { BallView ball = new BallView(getContext()); public DrawView(Context context) { this(context, null, 0); } public DrawView(final Context context, final AttributeSet attrs) { this(context, attrs, 0); } public DrawView(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); addView(ball); ball.setOnClickListener(this); } @Override public void onClick(View v) { Toast.makeText(getContext(), "Mock", Toast.LENGTH_SHORT).show(); } } </code></pre> <p><code>BallView</code> class stays the same.<br/> Layout:</p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"&gt; &lt;com.ruinalst.performance.tests.views.DrawView android:id="@+id/oscillator" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_centerInParent="true" /&gt; &lt;/RelativeLayout&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload