How make a layout available to a dialog
<p>In my activity there are 3 buttons. By clicking on the first button, I want a dialog to appear with a graph (in the layout itself it works fine).</p>

<pre><code> btn1 = (Button)findViewById(R.id.btn1);
        btn1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                 dialog = new Dialog(ChartsDuration.this);
                 dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                 dialog.setContentView(R.layout.dialog_charts1);     

// code to show a graph. Here I have a function that calls  drawChartAll(), 
// but since the layout is declared outside the dialog it cannot render it to the
// linearlayout, and my graph1 linearlayout will be empty.

                 dialog.show();


            }
        });
</code></pre>

<p>Tha graph uses data that are queried in functions outside like</p>

<pre><code>public void drawChartAll()
   {
//blablabla and this is how I define the layout and render the graph to it:
LinearLayout layout = (LinearLayout) findViewById(R.id.graph1);   
mChartView = ChartFactory.getBarChartView(ChartsDuration.this, buildBarDataset(titles, values),renderer,Type.DEFAULT);
mChartView.setBackgroundColor(renderer.getBackgroundColor());
layout.addView(mChartView);
}
</code></pre>

<p>So without the dialog, I can easily show the graph in the graph1 LinearLayout e.g below the buttons, because they are "on the same levels", but I want to show the graph in a dialog opened by clicking on a button. Because if I were in a dialog I would do this: <code>LinearLayout layout = (LinearLayout)dialog.findViewById(R.id.graph1);</code>   But now I cannot do this, since I am outside the dialog.</p>

<p>How do I reach this layout?</p>

<p><strong>Edit</strong>:</p>

<p>user113215 I did this:</p>

<p>in the activity:</p>

<pre><code> LayoutInflater inflater = LayoutInflater.from(ChartsDuration.this);
 customDialog = (ViewGroup) inflater.inflate(R.layout.dialog_charts1, null);


        btn1 = (Button)findViewById(R.id.btn1);
        btn1.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                 dialog.setContentView(customDialog);
                 //queries

                 dialog.show();


            }
        });
</code></pre>

<p>and in drawChartAll:</p>

<pre><code>   public void drawChartAll()
       {
    //code
     LinearLayout layout = (LinearLayout) customDialog.findViewById(R.id.graph1);
    }
</code></pre>

<p>Is this what you mean? This throws me a nullpointer exception to <code>dialog.setContentView(customDialog);</code> line.</p>
