이렇게 하면 그래프가 만들어지는데요;

이제 버튼 클릭 하면 보이게 하고 싶은데 하나도 모르겠어요;;

xml layout은 버튼 하나 View하나


package com.android.mathgraph;

import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MathGraph extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
       
        setContentView(R.layout.main);
       
        Button btn = (Button)findViewById(R.id.Button01);
       
        View TestView = (View)findViewById(R.id.View01);
        TestView tv = new TestView(this);
        setContentView(tv);
    }
}

class TestView extends View
{
    public TestView(Context context) {
        super(context);
    }
   
    public void onDraw(Canvas canvas)
    {
        Paint p = new Paint();    //그래프의 색
        p.setColor(Color.WHITE);
       
        Paint p1 = new Paint();    //기준선의 색, X축, Y축
        p1.setColor(Color.WHITE);
       
        float startingX = 160.0f;    //원점 X좌표
        float startingY = 240.0f;    //원점 Y좌표
       
        canvas.drawLine(0, startingY, 320, startingY, p1);
        canvas.drawLine(startingX, 0, startingX, 480, p1);
       
        float x=-160f ,y;
        y = (float) Math.pow(x, 2);
        float x1=x, y1=y;
       
        for(; x<=160.0f; x++)

        {
            y = (float) Math.pow(x, 2);
           
            canvas.drawLine(x1+startingX, -y1+startingY, x+startingX, -y+startingY, p);
           
            x1=x; y1=y;
        }
    }
}