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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T07:53:22+00:00 2026-05-20T07:53:22+00:00

I have a database with different results in my database in my Android project.

  • 0

I have a database with different results in my database in my Android project. I want to fetch these results and show them in a tablelayout. In the tablelayout I want to add a row for each result, and write the column “date” on one textview, and the “result” on the second textview. Both textviews are on the same row. I fetch the data and store it in a cursor.

My question is: How do I use the cursor and add a row depending on how much data there is in my database?

Right now I try to add a row for each row in the cursor like this:

TableLayout tl = (TableLayout)findViewById(R.id.table_layout2);
     TableRow tr = new TableRow(this);
     tr.setLayoutParams(new LayoutParams(
                             LayoutParams.FILL_PARENT,
                             LayoutParams.WRAP_CONTENT));
             TextView mTvDate = new TextView(this);
             TextView mTvResult = new TextView(this);
             int x=0;
             for(int i=0;i<c.getCount();i++){
             mTvDate.setText(date[x]);
             mTvResult.setText(""+nocorrect[x]+" av "+ noqs[x] +" ("+ proc[x]+ "%)");
             mTvDate.setLayoutParams(new LayoutParams(
                             LayoutParams.FILL_PARENT,
                             LayoutParams.WRAP_CONTENT));

             mTvResult.setLayoutParams(new LayoutParams(
                             LayoutParams.FILL_PARENT,
                             LayoutParams.WRAP_CONTENT));
             tr.addView(mTvDate);
             tr.addView(mTvResult);
     tl.addView(tr,new TableLayout.LayoutParams(
            LayoutParams.FILL_PARENT,
             LayoutParams.WRAP_CONTENT));
             }

But I think I need to create a NEW tablerow, cause I get this error message:

02-22 09:22:17.543: ERROR/AndroidRuntime(333): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

But I don’t want to remove it, I want to add more. Any ideas? Thanks!

  • 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-20T07:53:23+00:00Added an answer on May 20, 2026 at 7:53 am

    Hi try this
    i think you adding same row every time. so just declare it every loop iteration.

     TableLayout tl = (TableLayout)findViewById(R.id.table_layout2);
    
             int x=0;
             for(int i=0;i<c.getCount();i++){
     TableRow tr = new TableRow(this);
     tr.setLayoutParams(new LayoutParams(
                             LayoutParams.FILL_PARENT,
                             LayoutParams.WRAP_CONTENT));
             TextView mTvDate = new TextView(this);
             TextView mTvResult = new TextView(this);
             mTvDate.setText(date[x]);
             mTvResult.setText(""+nocorrect[x]+" av "+ noqs[x] +" ("+ proc[x]+ "%)");
             mTvDate.setLayoutParams(new LayoutParams(
                             LayoutParams.FILL_PARENT,
                             LayoutParams.WRAP_CONTENT));
    
             mTvResult.setLayoutParams(new LayoutParams(
                             LayoutParams.FILL_PARENT,
                             LayoutParams.WRAP_CONTENT));
             tr.addView(mTvDate);
             tr.addView(mTvResult);
     tl.addView(tr,new TableLayout.LayoutParams(
            LayoutParams.FILL_PARENT,
             LayoutParams.WRAP_CONTENT));
             }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two entities, each from a different database and therefore different edmx files.
I have a database that many different client applications (a smattering of web services,
What are the different database options on Windows Mobile available? I have used CEDB
I have the option of writing two different formats for a database structure: Article
I have a large ADO.Net dataset and two database schemas (Oracle) with different constraints.
I have databases with different collations. I want to be able to script out
I have a database where I store two different kinds of data. One table
I have a custom SQL call that is returning different results to the template
When I have two mysql servers that have different jobs (holding different databases) but
In my application I have several DataContexts that connects to different databases with different

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.