Search code examples
javaandroidandroid-layoutchartsjfreechart

Droid Charts Android Java Issue


I am following this android droid charts tutorial ...

http://w2davids.wordpress.com/creating-charts-with-droidcharts-for-android/

At one point he does this

setContentView(new XYLineChart(getApplicationContext()));

I want to specify an xml layout and then add this view to it ... How can I do that ? ...


Solution

  • Create an xml file 'linearlayoutgraph'.

    Then use the following code to call setContentView using this layout, while also adding other Views/Graph to it:

    public class Graph extends Activity{
    
        LinearLayout linearlayout;
    
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
                linearlayout = (LinearLayout) View.inflate(this, R.layout.linearlayoutgraph, null);
                ContentValues datasetDescription = new ContentValues();
                //add your graph
                xyLineChart mView = new xyLineChart(this, datasetDescription, createDataset());
                linearlayout.addView(mView);
                setContentView(linearlayout);
        }
    
    //create data
    private XYDataset createDataset()
    {
    }