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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:22:20+00:00 2026-06-09T11:22:20+00:00

I’m working on an Android app and I’ve got an Activity on which I

  • 0

I’m working on an Android app and I’ve got an Activity on which I am displaying two TableLayout’s on top of each other. The first TableLayout holds a scoreboard for a race (type 1) and the second the scoreboard for another race (type 2).

I inflate both of these TableLayout’s from the same XML layout file. I populate them with data from a doInBackground() (AsyncTask). However, the population part is pretty heavy, so I have put this into a custom synchronized method (inside the AsyncTask class) and pass the inflated TableLayout objects as an argument to this method.

I call said method from the doInBackground() method by using an ExecutorService object. This ExecutorService object is created with Executors.newSingleThreadExecutor(). I put the first method call in one Runnable and the second method call in another Runnable and fire off the ExecutorService.execute() on these runnables.

In the method I am accessing UI elements by calling findViewById() on the passed in TableLayout object parameter and calling methods like TextView.setText() on these views. This works fine most of the time, but I am starting to see a some exceptions like

ERROR/AndroidRuntime(409): FATAL EXCEPTION: pool-9-thread-1
    android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.

and

ERROR/AndroidRuntime(378): FATAL EXCEPTION: pool-2-thread-1
    java.lang.NullPointerException

which lets me to belive that I must be doing this incredibly backwards. I’ll include a simplified code snippet below to help describe what I am doing currently:

class AddRacesTask extends AsyncTask<Void, View, Void> {
    synchronized void populateTable(ArrayList<Race> data, TableLayout table) {
       TextView headerText = table.findViewById(R.id...);
       headerText.setText("Header");

       for(Race race : data) {
          TableRow row = getLayoutInflater().inflate(R.layout....);

          TextView pos = row.findViewById(R.id....);
          pos.setText(race.getPos());

          TextView person = row.findViewById(R.id....);
          person.setText(race.getPerson());

          // etc.
          // etc..
          // etc...

          table.addView(row);

       }

       publishProgress(table);

    }

    @Override
    private Void doInBackground(Void... voids) {
       ExecutorService executor = Executors.newSingleThreadExecutor();

       executor.execute(new Runnable() {
          @Override
          public void run() {
             TableLayout raceType1Layout = getLayoutInflater().inflate(R.layout...);
             populateTable(data, raceType1Layout);
          }
       });

       executor.execute(new Runnable() {
          @Override
          public void run() {
             TableLayout raceType2Layout = getLayoutInflater().inflate(R.layout...);
             populateTable(data, raceType1Layout);
          }
       });
    }

    @Override
    protected void onProgressUpdate(View... values) {
       if(values[0] instanceof TableLayout) {
          container.addView(values[0]);
       }
    }
}

I welcome any feedback at all. Also if you need more to go on, I’d be happy to post my actual source code but I figured a simplified and clean version would be easier.

  • 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-09T11:22:22+00:00Added an answer on June 9, 2026 at 11:22 am

    You need implement a custom Adapter that populate your custom view with Race object. You receive your data in background with custom thread or AsyncTask and pass to the UI thread via Handler or onPostExecute method respectively. Then, you can call Adapter.clear method and after

    for(Race r: ArrayList<Race>)
    Adapter.add(r) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.