Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I tried to implement the suggestions above, but could not get the functionality I was aiming for. Perhaps I've not framed my question completely, or just a general misunderstanding. I ended up adding a setBackgroundResource() in the myPainter main method to get the image on the screen. I think I've got it working as needed and posting the code below in case it helps someone else. Thanks for offering your help!</p> <pre><code> class myPainter extends View implements myConst { private final static String TAG = "** myPainter **"; public myPainter (Context context) { super (context); Log.d (TAG, "new myPainter"); setBackgroundResource (R.drawable.triangle); } @Override protected void onDraw(Canvas canvas) { super.onDraw (canvas); Log.d (TAG, "new myPainter"); Paint p = new Paint (); p.setColor (Color.RED); canvas.drawLine (E_XMIN, E_YMIN, E_XMAX, E_YMIN, p); } /** * called to determine what part of the triangle was clicked * @param x * @param y * @return click id from myConst */ private int getClick (float x, float y) { int id = 0; // insert logic to test x,y locations and return // region ID of what was clicked ... return (id); } @Override public boolean onTouchEvent (MotionEvent event) { Log.d (TAG, "touchevent in myPainter"); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: Log.d (TAG, "down x:" + event.getX() + " y:" + event.getY()); int wClick = getClick (event.getX(), event.getY()); break; } return false; } } </code></pre> <p>And then my main application class has this for onCreate():</p> <pre><code>/** Called when the activity is first created. */ @Override public void onCreate (Bundle savedInstanceState) { super.onCreate (savedInstanceState); setContentView (R.layout.main); myPainter mp = new myPainter(getApplicationContext()); mp.invalidate (); setContentView(mp); //ImageView iv = (ImageView) findViewById(R.id.ImageView01); //iv.setOnTouchListener (this); } </code></pre>
 

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