:) Thank you. I created an array of objects to fix the issue so have an array of circles the onDraw method is using.
On Aug 3, 7:13 pm, "Yusuf T. Mobile" <[email protected]> wrote: > The onDraw() function is the phone's way of asking you "so how do you > want me to draw this canvas, from scratch?" If you say "draw a circle > there!", you get one circle. If you want it to draw two circles, your > CustomDrawableView needs to tell it to draw two different circles > every time onDraw() is called, for example with two different > drawables. > > Yusuf Saib > Android > ·T· · ·Mobile· stick together > The views, opinions and statements in this email are those of the > author solely in their individual capacity, and do not necessarily > represent those of T-Mobile USA, Inc. > > On Aug 3, 6:30 am, Graham <[email protected]> wrote: > > > > > Hi, > > > I am new to the android developing world and have what I think is a > > very simple question. I have created a circle on a canvas and drawn it > > successfully. I now wish to add another circle to this already > > existing canvas in a different position. I have defined my x and y as > > arguments I pass to custom drawable view but when I try and get > > another circle drawn it just replaces the one that was already > > present. How do I keep the first circle and add on a second? > > > (My code below does not show trying to add another circle, it is > > simply what works with creating a single colour circle). > > > Thanks > > > G > > > package com.image; > > > import android.app.Activity; > > import android.os.Bundle; > > > public class image extends Activity { > > /** Called when the activity is first created. */ > > > private CustomDrawableView mCustomDrawableView; > > //private CustomDrawableView mCustomDrawableView2; > > > protected void onCreate(Bundle savedInstanceState) { > > super.onCreate(savedInstanceState); > > > //last argument 1 = green, all others = red > > mCustomDrawableView = new CustomDrawableView(this, 150, 40, > > "green"); > > setContentView(mCustomDrawableView); > > } > > > } > > > package com.image; > > > import android.content.Context; > > import android.graphics.Canvas; > > import android.graphics.drawable.ShapeDrawable; > > import android.graphics.drawable.shapes.OvalShape; > > import android.view.View; > > > public class CustomDrawableView extends View { > > private ShapeDrawable mDrawable; > > > public CustomDrawableView(Context context, int x, int y, String > > Colour) { > > super(context); > > > //int x = 80; > > //int y = 90; > > int width = 50; > > int height = 50; > > > mDrawable = new ShapeDrawable(new OvalShape()); > > if (Colour == "green"){ > > mDrawable.getPaint().setColor(0xff74AC23);//green > > } else if (Colour == "red") { > > mDrawable.getPaint().setColor(0xffff0000);//red > > } > > mDrawable.setBounds(x, y, x + width, y + height); > > } > > > protected void onDraw(Canvas canvas) { > > mDrawable.draw(canvas); > > } > > > }- Hide quoted text - > > - Show quoted text - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

