Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:27:01+00:00 2026-06-10T03:27:01+00:00

In my activity there are 3 buttons. By clicking on the first button, I

  • 0

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).

 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();


            }
        });

Tha graph uses data that are queried in functions outside like

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);
}

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: LinearLayout layout = (LinearLayout)dialog.findViewById(R.id.graph1); But now I cannot do this, since I am outside the dialog.

How do I reach this layout?

Edit:

user113215 I did this:

in the activity:

 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();


            }
        });

and in drawChartAll:

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

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:27:03+00:00Added an answer on June 10, 2026 at 3:27 am

    Make the dialogvariable a field in your Activity class. You can reach it from anywhere. You can still use dialog.findviewbyid throughout you Activity. Just make sure setcontentView has been called before you call findviewbyid

    Edit: I hope when you wrote since I am outside the dialog. you meant you could not access the variable

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my activity there is a toggle button. I want every time you change
I have an Activity which when clicking the menu and a button appearing there,
I have a problem on going back (clicking the Back button) from sub-activity to
I have a webview pat of my activity layout I have a button fullscreen
Alright, so i have an Activity. In the activity there is a textview and
In an android Activity is there a way to programmatically list the it has
here i am using an activity in which there is a list view,which I
Is there a way to vizualise the activity stack, at some moment during debug,
is there a way to create a task/activity report (say a weekly report) off
Is there a way to find out if an activity is bound to a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.