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

  • SEARCH
  • Home
  • 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 6529635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:39:32+00:00 2026-05-25T09:39:32+00:00

I have a graph view (custom view) in Android and a main view. Depending

  • 0

I have a graph view (custom view) in Android and a main view. Depending on the user’s preference I want to add 1-5 graph views onto my main view but am not quite sure how to. (I’m using purely Java and not xml). I was reading that I might have to use a Relative Layout or something in order to stack views.

Any advice or suggestions are welcome

  • 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-05-25T09:39:33+00:00Added an answer on May 25, 2026 at 9:39 am

    in your activity you probably have something like this towards the begining of your onCreate() method:

    setContentView(R.layout.main);
    

    inside your main.xml file you probably have an element that is some kind of layout. I will assume LinearLayout for now, but it works similarly with all types. You’ll need to get a reference to this layout and to do that it must have an id. So if that layout does not have something like this in it you need to add it:

    android:id="@+id/myMainLayout"
    

    Then back in your java sometime after you’ve called setContentView() you can find the reference to your layout with something like this:

    LinearLayout myLayout = (LinearLayout)findViewById(R.id.myMainLayout);
    

    Once you have a reference to your layout you can add your graph views to it with something like this:

    myLayout.addView(graph1);
    myLayout.addView(graph2);
    //etc...
    

    If you want to skip the xml layout all together you are allowed to make your layout in java. To do that it would like this:

    LinearLayout myLayout = new LinearLayout(YourActivity.this);
    myLayout.addView(graph1);
    myLayout.addView(graph2);
    setContentView(myLayout);
    

    Note that you can only call setContentView() once so you’ll need to pass some kind of Layout to it if you want to add more than 1 View.

    Edit:

    I have never specifically tried but I would think you could call addView() from the constructor in your custom view:

    public CustomView() {
        this.addView(anotherView);
    }
    

    do you have a custom view for your layout too?

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

Sidebar

Related Questions

I have a simple line graph which allows the user to view a section
I have a scrollview with sub-view of core-plot graph view. It does not zoom
I have this object graph, I want to map: abstract Account (username, password, ...)
I have a modal view controller that is presented from my main view, I
I have a custom view public GraphView(Context context, float[] values, String title, String[]horlabels, String[]
i have an interactive graph on my main form, when you click a child
I have one view controller set with one graph view and segmented control inside
I have a web application in which you view/explore a 2D network graph. when
I have a problem with accessing the graph API through my android application that
I have a UIPickerView that appears in a UIPopoverController atop a graph view. When

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.