I have a simple program to draw simple shapes by canvas.
private class MyViewCircle extends View {
public MyViewCircle(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
super.onDraw(canvas);
Paint paint = new Paint();
paint.setAntiAlias(true);
paint.setColor(Color.RED);
canvas.drawCircle(89, 150, 30, paint);
}
}
As you see, the attributes of the circle is
(Color.RED);
(89, 150, 30, paint);
I want to created another class includes a lot of other features(colors and coordinates) and select them randomly.
So, which way is better, array or arraylist or something else? Could someone gives me an example how to do that? Then how to randomly pick them and put them into the draw function? Cheers!
Try creating a simple Java object to contain all the attributes, then add them to a single list and choose an item at random:
In your View class: