0

I am trying to draw some lines on the background of an EditText.

I subclassed EditText, and included the fully qualified package name in my xml layout, replacing the previous EditText declaration.

Then I implemented onDraw(); but what is happening is that onDraw just seems to get called over and over again in an infinite loop.

I thought maybe I was launching an infinite recursion, so I commented everything out except for a log message, and it is still occurring.

What is going on here?

package myview;
import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.EditText;

public class LinedEditView extends EditText {

  public LinedEditView(Context context, AttributeSet attrs) {
    super(context, attrs);
  }

  public LinedEditView(Context context) {
    super(context);
  }

  public LinedEditView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
  }

  @Override
/////// KEEPS GETTING CALLED !!!!!!??????? ////////////
  protected void onDraw(Canvas canvas) {
    Log.d("LinedEditView", "Calling onDraw()");
    super.onDraw(canvas);
  }
}
4

1 回答 1

2

It looks like you are logging every time onDraw() is called, which conceivably should be once per frame (or else once per update required).

Usually the way an animation loop works is that it is exactly an infinite loop, which is called over and over again, and draws to the canvas depending on the state of the view at the time at which it is called.

于 2012-10-17T23:22:29.390 回答