• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Why won't my canvas display?

I'm fairly new to this whole graphics/canvas thing. All I'm trying to do is display a canvas with a line on it below some buttons. What have I done wrong? Here is my code:


Code:
public class Vectors extends Activity{

	VectorsView vectorsView;
	LinearLayout l;
	Canvas canvas;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.vectors);
		vectorsView = new VectorsView(this);

	}
	
	public class VectorsView extends View{

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

		@Override
		protected void onDraw(Canvas canvas) {
			// TODO Auto-generated method stub
			super.onDraw(canvas);
			l = (LinearLayout) findViewById(R.layout.vectors);
			
			
			Paint paint = new Paint();
			canvas = new Canvas();
			
			paint.setColor(Color.WHITE);
			canvas.drawLine(0, 0, 100, 100, paint);
			vectorsView.draw(canvas);
			
			l.addView(vectorsView);
			setContentView(l);
		}
	}
}
 
Back
Top Bottom