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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:51:18+00:00 2026-05-16T16:51:18+00:00

I have implemented the following function to be used with showDialog() and onDialogCreate(), but

  • 0

I have implemented the following function to be used with showDialog() and onDialogCreate(), but I would like the method to be called each time because it calculates the text of a text view every time the dialog is displayed.

private AlertDialog overallScoreDialog(){
    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    Context mContext = getApplicationContext();
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.overall_score_dialog,
            (ViewGroup) findViewById(R.id.overall_score_dialog_layout_root));
    alert.setTitle("Results");  

    TextView tv = (TextView) layout.findViewById(R.id.overallscoreresults);
    ScoreCalculator sc = new ScoreCalculator(this, calculatorVO);
    tv.setText(Double.toString(sc.getTotalScore()));

    alert.setView(layout);
    alert.setPositiveButton(R.string.done, new DialogInterface.OnClickListener() {  
        public void onClick(DialogInterface dialog, int whichButton) {
            return;                  
        }  
    });  

    AlertDialog ad = alert.create();
    return ad;
}

Can anyone help?

  • 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-16T16:51:19+00:00Added an answer on May 16, 2026 at 4:51 pm

    Activities will only call onCreateDialog once and keep references to each dialog. If you want to update a dialog you can override onPrepareDialog(int id, Dialog dialog) which is called every time showDialog is called.

    So for your example above where you update the TextView with the score you can do the following:

    @Override
    protected void onPrepareDialog(int id, Dialog dialog) {
        TextView tv = (TextView) dialog.findViewById(R.id.overallscoreresults);
        ScoreCalculator sc = new ScoreCalculator(this, calculatorVO);
        tv.setText(Double.toString(sc.getTotalScore()));
    }
    

    You may also want to keep the ScoreCalculator in a member variable so you don’t instantiate a new object everytime the dialog is shown.

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

Sidebar

Related Questions

Which of the following has the best performance? I have seen method two implemented
I would like to implement the following behaviour: I have a special media player,
I would like to implement the following scenario in Haskell. I have an enumerable
I have implemented the following set up (after being requested): slideshow of images changing,
I have the following tricky problem: I have implemented a (rather complicated) class which
Following the Google Tile Wrapper example, I have implemented a google MapView with an
I have the following problem: I implemented a managed mobile application for Windows Mobile
I have the following Strategy Pattern implemented: public abstract class RetrievalStrategy { public abstract
I have the following problem. I have a tabbed application implemented using a ViewPager.
In my project I have the following three interfaces, which are implemented by classes

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.