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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:47:27+00:00 2026-05-28T05:47:27+00:00

Let me start by explaining this is my first Android app. So I don’t

  • 0

Let me start by explaining this is my first Android app. So I don’t have a full grasp of all concepts yet. I expect this problem to relate to that lack of knowledge, but I can’t seem to google the solution to this issue this time.

I have this snippet of code to fetch some data from a remote Mysql database to fill a ListView with. This works just fine.

// fetch family and determine length of the arrays
Familielid[] familie = Mysql.getFamilie();
int len = familie.length;
namen = new String[len]; // groups
lijsten = new String[len][];  // children

// loop through the family and fill names and lists
for (int i=0; i<len; i++)
{
    namen[i] = familie[i].getNaam();
    Lijst lijst = new Lijst(Mysql.getLijst(familie[i].getId()));
    lijsten[i] = lijst.getOmschrijvingen();
}

Now because this can take some time, I want to show a progress bar that gets filled for each “Familielid” (= family member) that has been loaded. (I want to do it this way mainly to find out how to do it)
This code however, is throwing an application error. 🙁

// show progress bar while loading 
ProgressDialog progressDialog = new ProgressDialog(VerlanglijstenActivity.this);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setMessage("Lijstjes ophalen...");
progressDialog.setCancelable(false);
progressDialog.show();

// load lijstjes with progress bar
Thread loadLijstjes = new Thread(new Runnable() {
    public void run() {
        // fetch family and determine length of the arrays
        Familielid[] familie = Mysql.getFamilie(); 
        int len = familie.length;
        namen = new String[len]; // groups
        lijsten = new String[len][];  // children

        // loop through the family and fill names and lists
        for (int i=0; i<len; i++)
        {
            namen[i] = familie[i].getNaam();
            Lijst lijst = new Lijst(Mysql.getLijst(familie[i].getId()));
            lijsten[i] = lijst.getOmschrijvingen();
            // show progress
            progressDialog.incrementProgressBy((int) Math.floor(100/len));
        }
        progressDialog.setProgress(100); // just make sure it's 100% when we're done
        progressDialog.dismiss() ; // close the progress bar
    }
});
loadLijstjes.start();

Any idea what I’m doing wrong? Or should it be done entirely differently?

  • 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-28T05:47:28+00:00Added an answer on May 28, 2026 at 5:47 am

    Here’s a doc for an excellent start to some approaches to dealing with threading in Android. The source of your problem is that you are trying to update your UI from a non-UI thread. You can fix this most easily by handling your background work in an AsyncTask as described in the doc, and putting the progress updates in the onProgressUpdate method.

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

Sidebar

Related Questions

Let me start by explaining. I have a few global database connections and have
Let me start by saying I am new to Android development but have a
First let me start by explaining my use case: Say there is a database
Let me start by explaining our set-up: I am working with some contractors. They
Let me start by saying that I do not advocate this approach, but I
Let me start off with a bit of background. This morning one of our
Let me start by saying I'm a huge fan of the elegance of this
Let me start out by saying that I'm not a JavaScript developer so this
First off, let me start off that I am not a .net developer. The
I'm not sure if the question title is accurate... Let me start by explaining

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.