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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:19:58+00:00 2026-05-31T20:19:58+00:00

I am trying update text views while this loop is processing. Here is my

  • 0

I am trying update text views while this loop is processing. Here is my code that I am using for this activity.

public class StartDayActivity extends Activity {
Data data_;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.startdayscreen);            


    Thread seperationTimer = new Thread(){
        public void run(){
            int seperationTimer = 5000;
            int weatherAffect = 0;
            int randomEventAffect = 0;
            int locationTotalAvailable = 10;
            //int servingTime = 3000;
            int totalAvailableCustomers = (weatherAffect + randomEventAffect + locationTotalAvailable);
            int dayTimer = (totalAvailableCustomers * seperationTimer);
            int seperationTimerDay = 0;
            int lemonadeSold = 11;
            int totalDrinksSold = 0;
            int pitcherSize = 12;
            int totalLemonsUsed= 0;
            int totalIceUsed =0;
            int totalSugarUsed = 0;
            int totalCupsUsed = 0;
            double drinkPrice = 0.80;

            try{                    
                while(seperationTimerDay < dayTimer){  
                    sleep(seperationTimer);
                    seperationTimerDay = seperationTimerDay + seperationTimer;
                    lemonadeSold = lemonadeSold + 1;
                    totalDrinksSold += 1;
                    data_.cups_ -= 1;
                    totalIceUsed += 2;

                    if(lemonadeSold == pitcherSize){
                        lemonadeSold = 0;
                        data_.lemons_ -= 4;
                        data_.sugar_ -= 2;  
                        totalSugarUsed +=2;
                        totalLemonsUsed +=4;                            
                    }
                    if(data_.lemons_ == 0 || data_.ice_ == 0 || data_.sugar_ ==0 || data_.cups_ == 0){
                        break;
                    }

                    updateView();
                    Log.d("TAG", "for each : " + data_.ice_);
                    //calcMarketing();
                }

                    data_.day_gross_profit_ = (totalDrinksSold * drinkPrice);
                    data_.cash_ += (totalDrinksSold * drinkPrice);
                Intent i = new Intent("com.game.lemonade.PLAYSCREEN");
                startActivity(i);
            }
            catch(InterruptedException e)
            {
                e.printStackTrace();
            }  
            finally{
                finish();
            }

        }
    };
    seperationTimer.start();
}   

@Override
public void onStart(){
    super.onStart();
    data_ = getData();

}
@Override
public void onResume(){
    super.onResume();
    data_ = getData();
    //refreshDisplay();
}

@Override
public void onPause(){
    super.onPause();
    saveData();
    //refreshDisplay();
}

@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    //refreshDisplay();
}

private Data getData() {
    GameData player_data = new GameData(this);
    player_data.open();
    Data game_state = new Data(player_data.getGameString());
    player_data.close();
    return game_state;
  }

private void saveData() {
    GameData player_data = new GameData(this);
    player_data.open();
    player_data.setGameString(data_.SerializeGame());
    player_data.close();

}
private void updateView(){
    ((TextView)findViewById(R.id.lemonsLeftText2)).setText(
            (data_.lemons_) );
}
}

Is there a better way to try to do this? And how would I want to do that? I get an error when I do the updateView() to try to update textview.

  • 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-31T20:19:59+00:00Added an answer on May 31, 2026 at 8:19 pm

    You cant access the UI using threads directly.Either use an AsyncTask or Handler for your longer thread operations which effect the UI.

    Check these;

    http://developer.android.com/resources/articles/painless-threading.html

    http://developer.android.com/reference/android/os/Handler.html

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

Sidebar

Related Questions

I'm trying to update my text area via ActionScript code using this: scoreLabel.text =
I am trying to update the text of a UITextView programmatically. This was working
Im trying to update the contents of an element after running some php code.
So I'm trying to update an object in my MS SQL 2005 database using
I'm trying to create a sitemap that will automatically update. I've done something similiar
I'm just stumped on what to do with this code, I'm just trying to
I'm trying to make work this example from http://developer.android.com/resources/tutorials/views/hello-timepicker.html , no errors while compiling
I'm trying to programme an Android app that will update some TextViews as I
I stack with this, I'm trying to create application using TabLayout. I have 3
I'm trying to update a UITextView's text property, after a segue, which happens after

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.