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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:01:47+00:00 2026-06-14T14:01:47+00:00

I am adding dynamic row with textview in table layout, Also I want x

  • 0

I am adding dynamic row with textview in table layout, Also I want x y coordinates of that textview. For that I used view.getLocationOnScreen(loc) method.

But is showing only last item coordinates, I want to show all item coordinates.

This is my source code please help me for that.

Thanks you.

public class MainActivity extends Activity {
TextView tv1, tv2;
TableRow row;
TextView txt;
TableLayout tl;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tl = (TableLayout) findViewById(R.id.tableLayout1);
    for (int i = 0; i <= 15; i++) {
        row = new TableRow(this);
        txt = new TextView(this);

        tl.addView(row);
        row.addView(txt);
        readLocation();
    }
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    // TODO Auto-generated method stub
    super.onWindowFocusChanged(hasFocus);
    readLocation();
}

private void readLocation() {
    int[] locationOnScreen = new int[2];
    txt.getLocationOnScreen(locationOnScreen);
    txt.setText(locationOnScreen[0] + " : " + locationOnScreen[1]);
}

}

and my following xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TableLayout
        android:id="@+id/tableLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </TableLayout>
</ScrollView>

  • 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-14T14:01:49+00:00Added an answer on June 14, 2026 at 2:01 pm

    You shouldn’t try to get those coordinates in onCreate method in this way since layout procedures are not yet completed at this point.

    Here is a little bit modified demo base on your code:

    public class MainActivity extends Activity {
    
    ArrayList<TextView> txt = new ArrayList<TextView>();
    TableLayout tl;
    
    Handler _h = new Handler();
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    
        tl = (TableLayout) findViewById(R.id.tableLayout1);
        for (Integer i = 0; i <= 15; i++) {
            TableRow therow = new TableRow(this);
            TextView thetxt = new TextView(this);
    
            therow.addView(thetxt);
            tl.addView(therow);
    
            txt.add(thetxt);
    
            thetxt.setText("stub");
        }
    
        tl.requestLayout();
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
    
    @Override
    protected void onResume() {
        super.onResume();
        _h.postDelayed(new Runnable() {
    
            @Override
            public void run() {
    
                for (Integer i = 0; i <= 15; i++) {
    
                    TextView thetxt = txt.get(i);
    
                    int[] locationOnScreen = new int[2];
                    thetxt.getLocationOnScreen(locationOnScreen);
                    thetxt.setText(locationOnScreen[0] + " : " + locationOnScreen[1]);
                }        
    
    
            }
        }, 1000);
    
    }
    

    }

    The key point is postDelayed in onResume that lets the system to position all views correctly.

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

Sidebar

Related Questions

I am making a dynamic table that will add rows whenever the add row
I am adding dynamic row to table through JavaScript: var cell1 = row.insertCell(0); var
I have a panel, where my program is adding dynamic controls. Either I want
I created a dynamic table in ASP/VBScript that populates a table from a recordset.
I am adding a dynamic gradient that requires multi-browser CSS; it works if directed
I want to structure a table to mimic column level filters as row level
My table is populated by dynamic data, so I am adding TableRows and its
I got a query regarding adding dynamic buttons with dynamic onclick events on a
I'm trying to create a supervisor which handles adding dynamic gen_servers. for a reason
How would I go about adding a dynamic .......... to a restaurant menu in

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.