I want to implement chart like structure.
For bar graph I’m using no. of buttons in my main activity and hence the output is as following :

Then I’m creating new class which extends View in order to draw x and y axes for graph using canvas as following:
public class Draw extends View {
Paint paint = new Paint();
public Draw(Context context) {
super(context);
paint.setColor(Color.BLACK);
}
@Override
public void onDraw(Canvas canvas) {
canvas.drawLine(20, 50, 20, 200, paint);
canvas.drawLine(20, 200, 200, 200, paint);
}
}
But the problem is, after I use following lines of code in my main activity:
Draw draw = new Draw(this);
setContentView(draw);
I get following output as I’m setting the ContentView again:

So my question is how do I integrate both these views in order to get below output:

Is there any other way for doing the same?
ANY HELP APPRECIATED.
EDIT
Based on various suggestions, I removed
Draw draw = new Draw(this);
setContentView(draw);
from my activity class and instead put these lines in main xml layout.
<com.example.calci.Draw
android:id="@+id/draw"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
But I’m getting following EXCEPTION:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.calci/com.example.calci.CalciActivity}: android.view.InflateException: Binary XML file line #468: Error inflating class com.example.calci.Draw
Caused by: java.lang.NoSuchMethodException: Draw(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)
EDIT 2
By adding AttributeSet attributeSet to constructor, I got the desired result.
But can anyone suggest whether I should use buttons or rectangles from canvas to draw bar graph.
Please note that I need to modify the height of the bar graphs dynamically based on seekbar value.
If you are using xml for bar graph layout, you can include there your new created view like this:
More about using custom components: http://developer.android.com/guide/topics/ui/custom-components.html