To draw different geometric figure based on user option?
===

In my program user is asked for three options to draw a figure

Rectangle
Square
Circle

based on option the figure is drawn on canvas.

My porblem is that the figure is not displayed on canvas.

I cannot figure-out what is wrong and why the canvas is not drawing anything.

    DrawCanvas.java
    
    public class DrawCanvas extends View {
    	
    	private Paint bluePaint;
    	private String figure;
    	private Rect rect;
    	
    	public DrawCanvas(Context context, AttributeSet attrs) {
    		super(context, attrs);
    		rect = new Rect(150,200,150,200);
    		bluePaint = new Paint(Color.BLUE);
    		bluePaint.setStyle(Style.FILL);
    	}
    
    	@Override
    	protected void onDraw(Canvas canvas) {
    		super.onDraw(canvas);
    		if("Rectangle".equalsIgnoreCase(getFigure())) {
    			canvas.drawRect(rect, bluePaint);
    		}else if("Square".equalsIgnoreCase(getFigure())) {
    			canvas.drawRect(rect, bluePaint);
    		}else if("Circle".equalsIgnoreCase(getFigure())) {
    			canvas.drawCircle(150, 150, 25, bluePaint);
    		}
    	}
    
    	public String getFigure() {
    		return figure;
    	}
    
    	public void setFigure(String figure) {
    		this.figure = figure;
    	}
    
    }

In XML file i have included the custom view

XML file: activity_demo_app.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <com.example.demoapp.DrawCanvas
            android:id="@+id/drawCnavas"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/spinner1" />
    
        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:entries="@array/drawingOption" />
    
    </RelativeLayout>

the main activity class in which this layout is set is 

DemoAppActivity.java

    public class DemoAppActivity extends Activity {
    
    	DrawCanvas drawCanvas;
    	Bitmap bitmap;
    	Canvas canvas;
    
    	@Override
    	public void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_demo_app);
    		drawCanvas = (DrawCanvas) findViewById(R.id.drawCnavas);
    		drawCanvas.setBackgroundColor(Color.YELLOW);
    		bitmap = Bitmap.createBitmap(480, 250, Config.RGB_565);
    		canvas = new Canvas(bitmap);
    		Spinner drawingOptionsSpinner = (Spinner) findViewById(R.id.spinner1);
    		drawingOptionsSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
    
    			@Override
    			public void onItemSelected(AdapterView<?> arg0, View view,
    					int arg2, long arg3) {
    				final TextView textView = (TextView) view;
    				if(!"None".equalsIgnoreCase(textView.getText().toString())) {
    					if("Rectangle".equalsIgnoreCase(textView.getText().toString())) {
    						drawCanvas.setFigure(textView.getText().toString());
    						drawCanvas.draw(canvas);
    					}else if("Square".equalsIgnoreCase(textView.getText().toString())) {
    						drawCanvas.setFigure(textView.getText().toString());
    						drawCanvas.draw(canvas);
    					}else{
    						drawCanvas.setFigure(textView.getText().toString());
    						drawCanvas.draw(canvas);
    					}
    				}
    			}
    
    			@Override
    			public void onNothingSelected(AdapterView<?> arg0) {
    				// TODO Auto-generated method stub
    
    			}
    		});
    	}
    
    	@Override
    	public boolean onCreateOptionsMenu(Menu menu) {
    		getMenuInflater().inflate(R.menu.activity_demo_app, menu);
    		return true;
    	}
    
    
    }

There is no compile time error or any run time error.
But still the canvas does not draw the figures.

Can any bode help me on this.

Thanks and regards,
Allwyn Joseph.

