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 7968483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:05:06+00:00 2026-06-04T07:05:06+00:00

I am having trouble with View leader , I’m not sure what the second

  • 0

I am having trouble with View leader , I’m not sure what the second parameter is supposed to be

        TableLayout leaderTable = (TableLayout)findViewById(R.id.leaderTable);            

        TableRow tr = new TableRow(this);
        tr.setId(i);
        tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

        View leader = new View(UserView.this, null, R.id.leaderLayout);

        TextView number = (TextView)leader.findViewById(R.id.numberView);
        number.setText(String.valueOf(i+1));

        tr.addView(leader);

        leaderTable.addView(tr);

The problem is that my TextView is null, despite being a subview of leader.

Pretty confused about this issue, and this is my XML

<TableLayout 
                 android:id="@+id/leaderTable"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center">

            </TableLayout>

do I need to do more with the XML? I don’t have need to include the tablerows in it do I?

R.id.leaderLayout is its own xml file, a linearlayout with that id

  • 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-04T07:05:07+00:00Added an answer on June 4, 2026 at 7:05 am

    Here’s the developer page for the View constructors:

    https://developer.android.com/reference/android/view/View.html#View%28android.content.Context%29

    The second and third parameters for a View are used if you want this view to have certain attributes or styles set upon the creation of that view.

    It looks like you actually want your variable leader to be inflated. This will take a layout defined in xml and assign it to dynamically created view. You said that your leaderLayout is a LinearLayout, so it would look something like this.

    //Initialize the layout inflator, do this once and use it to inflate as many views as you want
    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    
    //Assign your custom view to the variable leader
    LinearLayout leader = (LinearLayout) inflator.inflate(R.layout.leaderLayout, tr); 
    

    The first parameter for inflate is R.layout.nameOfYourXmlFile. The second is the ViewGroup that will be the parent of your inflated View. Once this is done, you can use findViewById on leader to get the child views in your Xml file, add more children dynamically, and add it as a child of your TableRow.

    Here’s the developer page for LayoutInflator, in case you’re curious about other usages of the inflate method.

    http://developer.android.com/reference/android/view/LayoutInflater.html

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

Sidebar

Related Questions

Having trouble here and not quite sure how to do it. I've attempted jQuery
I'm having trouble navigating to a different controller view from another controller action. e.g.
I am having trouble programmatically removing stacks from a view. I am doing things
I am having trouble getting my modal view controllers to display properly. I have
I'm having trouble getting ember to render a dynamic child view. It seems that
I'm having some serious trouble understanding the view matrix in XNA. I've come pretty
Having trouble with the following segment of code. I'm getting a parameter count mismatch.
I'm having trouble sending data to a different view using the prepareForSegue method… I
I'm having trouble with and RSpec view test. I'm using nested resources and the
I'm using Model-View-Presenter framework. When Loading a page, I'm having trouble setting the selected

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.