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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:03:10+00:00 2026-06-05T14:03:10+00:00

I populate TableLayout in OnCreate(..) method. I’d like to get width of each column

  • 0

I populate TableLayout in OnCreate(..) method.
I’d like to get width of each column of the table.
The problem is during OnCreate(...) method view has width set to 0.
Where is correct place to collect table widths?

I also tried OnStart(...) (from doc “Called when the activity is becoming visible to the user.”) but the result was the same.

simpler example shows the problem (differ from upper description):

package xliiv.hello;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class __helloworldActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        tv = (Button) findViewById(R.id.button1);
        int width = tv.getWidth();
        //this width will be 0! I expect that textview widths is not 0
        Log.i("tag", "" + width);
    }
  • 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-05T14:03:13+00:00Added an answer on June 5, 2026 at 2:03 pm

    You should do this in onWindowFocusChanged() , That will give the exact width

    Try this:

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        // TODO Auto-generated method stub
        super.onWindowFocusChanged(hasFocus);
    
        int width = findViewById(R.id.button1).getWidth();
    
        Log.i("tag", "" + width);
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I populate a DataGrid from a CollectionViewSource. Each row has a delete button. On
I am trying to populate a List<Image> by reading the name of the each
I have a simple problem for Android. I'd like to create an n by
I have a table layout that I want to populate with the result from
I'm trying to populate a class object with values from a database table. The
Populate php array into HTML table I have data in a php array (say,
I populate the data from my table using a loadResults routine which runs on
I'd like to populate an arraylist by specifying a list of values just like
Or do you populate your form controls manually by a method? Is either considered
I have an app that has a viewflipper to keep tabs in view at

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.