1

I'm building a crossword game. Ideally, I would like to use similar functionality like the code below. However, I just need help figuring out how to draw a textfield on the screen so the user can input his/her words. Here's the code I have so far. How would I modify this code to draw a textfield instead of paint? Appreciate any help.

public class Word extends View {
    private Paint paint = new Paint();
      private Path path = new Path();

      public Word(Context context, AttributeSet attrs) {
        super(context, attrs);



        paint.setAntiAlias(true);
        paint.setStrokeWidth(30f);
        paint.setColor(Color.GRAY);
        paint.setStyle(Paint.Style.STROKE);
        paint.setStrokeJoin(Paint.Join.ROUND);
      }


      @Override
      protected void onDraw(Canvas canvas) {
        canvas.drawPath(path, paint);
      }

      @Override
      public boolean onTouchEvent(MotionEvent event) {
        float eventX = event.getX();
        float eventY = event.getY();

        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
          path.moveTo(eventX, eventY);
          return true;
        case MotionEvent.ACTION_MOVE:
          path.lineTo(eventX, eventY);
          break;
        case MotionEvent.ACTION_UP:

          break;
        default:
          return false;
        }

        // Schedules a repaint.
        invalidate();
        return true;
      }
wyguy321
  • 27
  • 5

1 Answers1

0

Use a TextView in addition to your "Word" view, and set its visibility to GONE, until you need it to show, then set it to VISIBLE when you want it.

Bob
  • 2,586
  • 7
  • 20
  • 33
  • Yea that's a good idea. However, I'm trying to figure how to pass a textfield object into the .drawPath method. Any suggestions? – wyguy321 Nov 04 '13 at 03:56
  • You can draw pretty much whatever you want to a canvas, however that is all you can do with it, you can't draw a View into a canvas, you can draw something that looks like a view, but it will just be like a picture of the view, it will not be functional unless you also implement all of it's functionality yourself. – Bob Nov 04 '13 at 09:00