Try adding invalidate() in your translate() method instead of
this.draw(_myCanvas);.

On Oct 25, 2:37 pm, "stephane.cast...@gmail.com"
<stephane.cast...@gmail.com> wrote:
> Hi!
> I have a problem with one of my app. I try to make a paint application
> but nothing is draw on the screen (except the first circle which is
> draw on the launch).
> The log Cat seems to be correct and i get the right x/y coordinates. I
> think i do something wrong on the ondraw.
>
> do you see my problem?
>
> Thanks.
>
> this is my code :
>
> public class Main extends Activity {
>     /** Called when the activity is first created. */
>
>         private TableLayout myView;
>
>     @Override
>     public void onCreate(Bundle savedInstanceState) {
>         super.onCreate(savedInstanceState);
>         Log.i("onCreate", " Start");
>         setContentView(R.layout.main);
>         myView= (TableLayout)findViewById(R.id.TableLayout01);
>         myView.addView(new PaintView(this));
>     }
>
> }
>
> public class PaintView extends View implements OnTouchListener {
>
>         private float _x, _y;
>         private int _taille;
>         private Canvas _myCanvas;
>         private Paint _paint = new Paint(Paint.ANTI_ALIAS_FLAG);
>         public PaintView(Context context){
>                 super(context);
>                 Log.i("Info", "_paintview Constructor 1");
>                 //this.setFocusableInTouchMode(true);
>                 _x=20;
>                 _y=20;
>                 _taille = 10;
>                 _paint.setColor(Color.RED);
>         }
>
>         public PaintView(Context parent, float x, float y, int i) {
>                 super(parent);
>                 Log.i("Info", "_paintview Constructor");
>                 _x=x; _y=y; _taille = i;
>                 _paint.setColor(Color.RED);
>
>         }
>
>         @Override
>         protected void onDraw(Canvas canvas) {
>                 Log.i("Info ","onDraw start");
>                 try{
>                         // make the entire canvas white
>                         canvas.drawColor(Color.WHITE);
>
>                         canvas.drawCircle(_x, _y, _taille, _paint);
>                         super.onDraw(canvas);
>
>                         Log.i("Info ","x="+_x+" y="+_y);
>                         _myCanvas=canvas;
>                 }
>                 catch(Exception e)
>                 {
>                         Log.i("ERROR", "onDraw : " + e.getMessage());
>                 }
>         }
>
>         public void translate(float x, float y){
>                 try{
>                         _x=x;
>                         _y=y;
>                         this.draw(_myCanvas);
>                 }
>                 catch (Exception e){
>                         Log.i("ERROR", " "+e.getMessage());
>                 }
>         }
>
>         @Override
>         public boolean onTouchEvent(MotionEvent evt){
>                 translate(evt.getX(), evt.getY());
>                 return true;
>         }
>
>         @Override
>         public boolean onTouch(View v, MotionEvent evt) {
>                 translate(evt.getX(), evt.getY());
>                 return false;
>         }
>
>
>
> }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to