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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T00:43:26+00:00 2026-06-15T00:43:26+00:00

I want to show the ProgressDialog when user clicks the gridview in the Fragment.

  • 0

I want to show the ProgressDialog when user clicks the gridview in the Fragment. ProgressDialog must show till the next activity loads. I have Google many times and in SO also, but can’t solution exact like my problem. Till my work is,

My Fragment class:

@TargetApi(11)
public void onActivityCreated(Bundle savedInstanceState)
{
    super.onActivityCreated(savedInstanceState);
    gridView.setAdapter(new ImageAdapterTwo(Constant.getContext(),countries1));
    gridView.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View v,
            int position, long id) {
        System.out.print("gridView.getId();=="+gridView.getId()) ;
        if(v==null)
        {
            System.out.print("gridView.getId();=="+gridView.getId()) ;
        }
        else
        {
            TextView t=(TextView) v.findViewById(R.id.grid_item_text);
            if(t==null)
            {
                System.out.print("gridView.getId();==") ;
            }
            else
            {
                if(t.getText()=="")
                {
                    new Task().execute();
                }
                else if(t.getText()=="")
                {
                    Intent i2 = new Intent(Constant.getContext(), ServerBackup.class);  
                    startActivity(i2);
                }
                else if(t.getText()=="")
                {
                    Intent i2 = new Intent(Constant.getContext(), ServerBackup.class);  
                    startActivity(i2);
                }
                else
                {
                    Intent i2 = new Intent(Constant.getContext(), ViewPagerFragmentActivity.class);  
                    startActivity(i2);
                }
            }
        }
    }
});
}

Task.java:

package com.net.elderlyhealth.weather;

import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.util.Log;

import com.net.elderlyhealth.weather.AsyncClass;


public class Task extends AsyncTask<Void, Void, String>
{
    Context context;
    AsyncClass asyncclass=new AsyncClass();
    //context=Constant.getContext();
    public Task(Context context)
    {
        //this.context=context;
        //Log.d("context",context.toString());
    }
    @Override
    protected void onPreExecute()
    {
        asyncclass.showLoadingProgressDialog();
    }

    @Override
    protected String doInBackground(Void... params)
    {
        Intent intent=new Intent(context,ActivityWeatherSetting.class);
        context.startActivity(intent);
        return null;
    }

    @Override
    protected void onPostExecute(String params)
    {
        asyncclass.dismissProgressDialog();
    }
}

AsyncClass.java:

import android.app.Activity;
import android.app.ProgressDialog;

public class AsyncClass extends Activity
{
    protected static final String TAG = AsyncClass.class.getSimpleName();

public ProgressDialog progressDialog;

private boolean destroyed = false;

@Override
protected void onDestroy()
{
    super.onDestroy();
    destroyed = true;
    /*if ( progressDialog!=null && progressDialog.isShowing() ){
        progressDialog.cancel();
    }*/
}

public void showLoadingProgressDialog()
{
    this.showProgressDialog("Loading. Please wait...");
}

public void showProgressDialog(CharSequence message)
{
    if (progressDialog == null)
    {
        progressDialog = new ProgressDialog(this);
        progressDialog.setIndeterminate(true);
    }

    progressDialog.setMessage(message);
    progressDialog.show();
}

public void dismissProgressDialog()
{
    if (progressDialog != null && !destroyed)
    {
        progressDialog.dismiss();
    }
}
}

Logcat:

11-16 14:03:31.744: E/AndroidRuntime(2246): FATAL EXCEPTION: main
11-16 14:03:31.744: E/AndroidRuntime(2246): java.lang.NullPointerException
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.content.ContextWrapper.getApplicationInfo(ContextWrapper.java:132)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.view.ContextThemeWrapper.getTheme(ContextThemeWrapper.java:65)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.app.AlertDialog.<init>(AlertDialog.java:98)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.app.ProgressDialog.<init>(ProgressDialog.java:77)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at com.net.elderlyhealth.weather.AsyncClass.showProgressDialog(AsyncClass.java:33)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at com.net.elderlyhealth.weather.AsyncClass.showLoadingProgressDialog(AsyncClass.java:26)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at com.net.elderlyhealth.weather.Task.onPreExecute(Task.java:24)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:561)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.os.AsyncTask.execute(AsyncTask.java:511)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at com.net.elderlyhealth.view.SampleGridTwoFragment$1.onItemClick(SampleGridTwoFragment.java:126)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.widget.AdapterView.performItemClick(AdapterView.java:292)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.widget.AbsListView.performItemClick(AbsListView.java:1058)
11-16 14:03:31.744: E/AndroidRuntime(2246):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:2514)

Where i am going wrong?

  • 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-15T00:43:27+00:00Added an answer on June 15, 2026 at 12:43 am

    Modified code for async task

    import android.content.Context;
    import android.content.Intent;
    import android.os.AsyncTask;
    import android.util.Log;
    
    import com.net.elderlyhealth.weather.AsyncClass;
    
    
    public class Task extends AsyncTask<Void, Void, String>
    {
    Activity currentActivity;
    ProgressDialog dialog;
    public Task(Activity activity)
    {
    currentActivity = activity;
    }
    
    @Override
    protected void onPreExecute()
    {
    dialog=ProgressDialog.show(currentActivity, "Title", "Msg");
    }
    
    @Override
    protected String doInBackground(Void... params)
    {
    //do your work
    }
    
    @Override
    protected void onPostExecute(String params)
    {
    dialog.dismiss();
    }
    }
    

    Calling the async task

    new Task(getActivity()).execute()

    This should solve your problem.
    Keep in mind you cannot just instantiate a class which extends activity and expect it to perform UI operation.

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

Sidebar

Related Questions

I have an Activity where I want to show a ProgressDialog. I override onCreateDialog
Possible Duplicate: Android: ProgressDialog.show() crashes with getApplicationContext I want to have a progress dialog
ProgressDialog onClick not working.. here is my code .. Basically i want to show
I want to show ProgressDialog when I click on Login button and it takes
i want to show a PD when my activity A starts another activity B.
protected void showSpinner() { dialogSpin = ProgressDialog.show(activity, , Loading. Please wait..., true); Thread t
I have this code below and want it to show the progress of a
I want to show a circle progressdialog when some functions run in backstage. so
I have an Activity A1 and a ListActivity A2 I take inputs from user
I want ProgressDialog to show while my code enables WiFi and connects to a

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.