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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:21:48+00:00 2026-05-19T12:21:48+00:00

Let me sum up the situation for you: I have a button (btnChooseEp), and

  • 0

Let me sum up the situation for you:

  • I have a button (btnChooseEp), and when you press it an AlertDialog appears.
  • When something is picked in the AlertDialog, three if statements must be evaluated.
  • While they are being evaluated, a ProgressDialog appears. It indicates that the app is “busy”.
  • After the evaluation of these statements, the ProgressDialog must disappear.

My problem is described beneath the code.

The entire code block is shown here:

ProgressDialog getTracklistProgressDialog = null;

…

    Button btnChooseEp = (Button)findViewById(R.id.btnChooseEp);
    btnChooseEp.setOnClickListener(new OnClickListener()
    {           
        public void onClick(View v)
        {               
            final AlertDialog.Builder builder = new AlertDialog.Builder(GA.this);
            builder.setTitle(getText(R.string.chooseEpisode));
            builder.setItems(episodes, new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, final int pos)
                {                       
                    getTracklistProgressDialog = ProgressDialog.show(GA.this, "Please wait...",
                            "Retrieving tracklist...", true);

                    new Thread()
                    {
                        public void run()
                        {
                            try
                            {                       
                                String str1, epURL;

                                if(pos < 9)
                                {
                                    str1 = getResources().getString(R.string.epNo1);        
                                    epURL = String.format(str1, pos+1);
                                    setTracklist(epURL, tracklist);                 
                                }
                                else if(pos < 100)
                                {
                                    str1 = getResources().getString(R.string.epNo2);
                                    epURL = String.format(str1, pos+1);
                                    setTracklist(epURL, tracklist);
                                }
                                else if(pos >= 100)
                                {
                                    str1 = getResources().getString(R.string.epNo3);
                                    epURL = String.format(str1, pos+1);
                                    setTracklist(epURL, tracklist);
                                }
                            }
                            catch(Exception e)
                            {}

                            // Remove progress dialog
                            getTracklistProgressDialog.dismiss();                               
                        }
                    }.start();                          
                }
            });
            AlertDialog alertDialog = builder.create();
            alertDialog.show();
        }
    });

Not sure if needed, but here is the code for the function setTracklist:

public void setTracklist(String string, TextView tv)
{
    try
    {
        tv.setText(getStringFromUrl(string));
    }
    catch(Exception e)
    {
        e.printStackTrace();
    } 
}

And the code for the function getStringFromUrl can be seen here: http://pastebin.com/xYt3FwaS

Now, the problem:
Back when I didn’t implement the ProgressDialog thing (which I have from here, btw: http://www.anddev.org/tinytut_-_displaying_a_simple_progressdialog-t250.html), it worked fine – the setTracklist function retrieves a string from a text file on the internet, and sets the text to a TextView. Now, when I have added the ProgressDialog code, and put the original code into the try statement, only a very little part of the text file is added to the TextView – approximately 22-24 characters, not more. The “busy” ProgressDialog shows up just fine. It worked perfectly before; it was more than capable of loading more than 1300 characters into the TextView.
I don’t know if it has anything to do with the thread – I have Googled a lot and found no answer.

So, how do I get it to load in all data instead of just a small part?

(By the way, I would love to be able to set the line “setTracklist(epURL, tracklist);” beneath all of the if statements, but then it says it can’t resolve “epURL”. Seems stupid to write the same line 3 times!)

Updated 25/1 with current code:

final Handler uiHandler = new Handler();
final Button btnChooseEp = (Button)findViewById(R.id.btnChooseEp);
btnChooseEp.setEnabled(false);
btnChooseEp.setOnClickListener(new OnClickListener()
{           
        public void onClick(View v)
        {               
            builder.setTitle(getText(R.string.chooseEpisode));
            builder.setItems(episodes2, new DialogInterface.OnClickListener()
            {
                public void onClick(DialogInterface dialog, final int pos)
                {                       
                    replay.setVisibility(View.VISIBLE);
                    replayWeb.setVisibility(View.VISIBLE);

                    getTracklistProgressDialog = ProgressDialog.show(GA.this, "Please wait...",
                            "Retrieving tracklist...", true);

                    new Thread()
                    {
                        public void run()
                        {
                            try
                            {                       
                                String str1, epURL;

                                if(pos < 9)
                                {
                                    str1 = getResources().getString(R.string.gaEpNo1);      
                                    epURL = String.format(str1, pos+1);
                                    setTracklist2(epURL, tracklist);                    
                                }
                                else if(pos < 100)
                                {
                                    str1 = getResources().getString(R.string.gaEpNo2);
                                    epURL = String.format(str1, pos+1);
                                    setTracklist2(epURL, tracklist);
                                }
                                else if(pos >= 100)
                                {
                                    str1 = getResources().getString(R.string.gaEpNo3);
                                    epURL = String.format(str1, pos+1);
                                    setTracklist2(epURL, tracklist);
                                }
                            }
                            catch(Exception e)
                            {}

                            // Remove progress dialog
                            uiHandler.post(new Runnable()
                            { 
                                public void run()
                                { 
                                    getTracklistProgressDialog.dismiss();                                       
                                }
                            }
                            );                              
                        }
                    }.start();                          
                }
            });
            AlertDialog alertDialog = builder.create();
            alertDialog.show();
        }
    });

public void setTracklist2(final String string, final TextView tv)
{
    try
    {
        uiHandler.post(
                new Runnable()
                {
                    public void run()
                    {
                        try
                        {
                            tv.setText(getStringFromUrl(string));
                        }
                        catch (UnsupportedEncodingException e)
                        {
                            e.printStackTrace();
                        }
                    }
                });
    }
    catch(Exception e)
    {
        e.printStackTrace();
    } 
}

Notes: “replay” and “replayWeb” are just two TextView’s. “btnChooseEp” is enabled when another button is pressed.

  • 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-19T12:21:48+00:00Added an answer on May 19, 2026 at 12:21 pm

    My guess is that you are getting bizarre behavior because you are invoking a ui method on a non-ui thread.
    getTracklistProgressDialog.dismiss();
    must be executed on a ui thread. My guess is that it is crashing and your thread is crashing then leaving some of your resources in a bad state. This would explain why you get a varying amount of characters.

    I would try creating a final Handler in your onCreate method which would get bound to the uiThread. In that thread, you can then call

    uiHandler.post( 
     new Runnable() { 
      public void run(){ 
        getTracklistPRogressDialog.dismiss();
      }
     }
    );
    

    This is quick, so it may not be syntactically correct, check your ide.

    This is the best i can get from what you’ve posted. If you post more of the code I can try to run it to give you more help.

    Update:

    I think I found your problem:

    The idea of having another thread is to do the long running work there, but what we have right now actually does the long running work on the ui thread, the opposite of our goal. What we need to do is move the call to getStringFromUrl(url) from the setTracklist call up into the thread. I would rewrite setTracklist as follows:

    public void setTracklist(String tracklistContent, TextView tv)
    {
        try
        {
          runOnUiThread(
            new Runnable() {
              public void run() {
                tv.setText(tracklistContent);
              }
             });
        }
        catch(Exception e)
        {
            e.printStackTrace();
        } 
    }
    

    Then in your inner onClick method, do this:

                public void onClick(DialogInterface dialog, final int pos)
                {                       
                    getTracklistProgressDialog = ProgressDialog.show(GA.this, "Please wait...",
                            "Retrieving tracklist...", true);
    
                    new Thread()
                    {
                        public void run()
                        {
                            try
                            {                       
                                String str1, epURL;
    
                                if(pos < 9)
                                {
                                    str1 = getResources().getString(R.string.epNo1);        
                                    epURL = String.format(str1, pos+1);
                                    String tlContent = getStringFromUrl(epUrl);
                                    setTracklist(epURL, tracklist);                 
                                }
                                else if(pos < 100)
                                {
                                    str1 = getResources().getString(R.string.epNo2);
                                    epURL = String.format(str1, pos+1);
                                    String tlContent = getStringFromUrl(epUrl);
                                    setTracklist(epURL, tracklist);
                                }
                                else if(pos >= 100)
                                {
                                    str1 = getResources().getString(R.string.epNo3);
                                    epURL = String.format(str1, pos+1);
                                    String tlContent = getStringFromUrl(epUrl);
                                    setTracklist(epURL, tracklist);
                                }
                            }
                            catch(Exception e)
                            {}
    
                            // Remove progress dialog
                            getTracklistProgressDialog.dismiss();                               
                        }
                    }.start();                          
                }
    

    I’m so, we make the call to the web service/url before we regain ui thread execution. The long running internet retrieval runs on the bg thread and then the ui update happens on the ui thread. Think this should help.

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

Sidebar

Related Questions

Let's say I have something like this: select sum(points) as total_points from sometable where
Let's say I have a select Statement with the following: SUM(st.tafPoints/200) as totalFriendReferrals, SUM(CASE
Let us say I have the following script, calculating a sum. Here is the
The situation: Let's say I have an image A, say, 512x512 pixels, and image
Given that I have the array Let Sum be 16 dintptr = { 0
Let's say I have the following 2 queries: select sum(cast(2666 as float)) * cast(.3
I have to find the lowest possible sum from numbers' difference. Let's say I
Let's say I have these two functions: function z(a,b,c){ $(#d).click(function(){ var sum = a+b+c;
Let's have an example like below: package xliiv.sandbox; import android.app.Activity; import android.os.Bundle; import android.util.Log;
Let's say I don't have photoshop, but I want to make pattern files (.pat)

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.