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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:46:08+00:00 2026-06-01T09:46:08+00:00

In my Application I need to call a function(Which update the valuesof textviews),I need

  • 0

In my Application I need to call a function(Which update the valuesof textviews),I need to call this function inside AlertDialg when OK button is pressed.

the issue is how i can call RefreshData.execute() after ok button of dialog is pressed ?
this is one of the Errors :
android.view.WindowManager$BadTokenException: Unable to add window — token null is not for an application.

the code:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.details);

        Bundle extras = getIntent().getExtras();

        if (extras != null) {
            x = extras.getString("key").toString();
        } else {

            Toast.makeText(getBaseContext(), "null", 0).show();
        }

        tv_summary = (TextView) findViewById(R.id.tv_summary);
        tv_servings_result = (TextView) findViewById(R.id.tv_servings_result);
        tv_calories_result = (TextView) findViewById(R.id.tv_calories_result);
        tv_fat = (TextView) findViewById(R.id.tv_fat);
        tv_monofat = (TextView) findViewById(R.id.tv_monofat);
        tv_satfat = (TextView) findViewById(R.id.tv_satfat);
        tv_ch = (TextView) findViewById(R.id.tv_ch);
        tv_sug = (TextView) findViewById(R.id.tv_sug);

        new LoadDetails().execute();

        Button MealSize = (Button) findViewById(R.id.btn_size);

        MealSize.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                show();

                Toast.makeText(getBaseContext(), F + "", 0).show();
            }

        });

    }

    void Refresh() {
        new RefreshData().execute();
    }

    void show() {

        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("Title");
        alert.setMessage("Message");

        final EditText input = new EditText(this);
        alert.setView(input);
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

                F = Float.parseFloat(input.getText().toString());
                new RefreshData().execute();

            }
        });

        alert.setNegativeButton("Cancel",
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        // Canceled.
                    }
                });

        alert.show();

    }

    private class RefreshData extends AsyncTask<Void, Void, Void> {

        private ProgressDialog progressDialog;

        @Override
        protected void onPreExecute() {
            this.progressDialog = ProgressDialog.show(getBaseContext(), "",
                    " Loading...");
        }

        @Override
        protected void onPostExecute(final Void unused) {

            this.progressDialog.dismiss();

            try {
                this.progressDialog.dismiss();
                tv_servings_result.setText(servings_result + "" + F);
                tv_calories_result.setText(cal + "g");
                tv_fat.setText(ff + "");
                tv_monofat.setText(mm + "");
                tv_satfat.setText(sasa + "");
                tv_ch.setText(chch + "");
                tv_sug.setText(sugar + "");

            } catch (Exception e) {
                Log.e("log_tag",
                        "Eraaaaaaaaaaaaaaaaaaa connection" + e.toString());

            }

        }

        @Override
        protected Void doInBackground(Void... params) {

            try {
                sugar = Float.valueOf(sug).floatValue();
                sugar *= F;

                cal = Float.valueOf(calories_result).floatValue();
                cal *= F;

                ff = Float.valueOf(fat).floatValue();
                ff *= F;

                mm = Float.valueOf(monofat).floatValue();
                mm *= F;

            } catch (Exception e) {
                Log.e("log_tag",
                        "Eraaaaaaaaaaaaaaaaaaa connection" + e.toString());

            }

            return null;

        }

    }

}

  • 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-01T09:46:09+00:00Added an answer on June 1, 2026 at 9:46 am

    instead using

    this.progressDialog = ProgressDialog.show(getBaseContext(), ""," Loading...");
    

    try with

    this.progressDialog = ProgressDialog.show(yourActivity.this, ""," Loading..."); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call some PL/SQL procedures from my Java application. I can do
I need to perform asp.net web-service function call via jQuery and pass asp.net application
TL;DR Summary: I need a single command-line application which I can use to get
For a application with a database in C#, I need to call a function
I am creating a Console Application, in that I need to Call a Method,
I've an application where, for testing, I need to replace the time.time() call with
I have a Silverlight 3 application which needs to call WCF service. The WCF
In external (Delphi-created) DLL I've got the following function that I need to call
I need to call a script from a controller function, but I am not
In my flex application I use services a lot. I need them to update

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.