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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:28:37+00:00 2026-05-24T21:28:37+00:00

I use an ArrayAdapter to show items in a ListView. Every row in this

  • 0

I use an ArrayAdapter to show items in a ListView. Every row in this ListView owns a button.

Whenever the user clicks on one of these buttons I start an AsyncTask to do some processing in the background.

This is working so far.

Now I want to show a custom ProgressDialog during this time. What puzzles me here is the first parameter of the static convinience method ProgressDialog.show(). Within an activity I usually use “Activityname.this” here. But what should I use in an adapter. I tried context from the adapter (that crashed), context.getApplicationContext and several more. Nothing worked – either crashed or is refused from the compiler.

So my question today: What should I put into this parameter?

Here’s a stripped down part of my code:

public class MyAdapter extends ArrayAdapter<MyContainer> {

  private class MyAsyncTask extends AsyncTask<String, Void, Boolean> {

    @Override
    protected void onPreExecute () {
      if (!isRunning) {
        progressDialog = MyProgressDialog.show(?????,
                                               null,
                                               null,
                                               true,
                                               false);
      }
    }

    @Override
    protected Boolean doInBackground(final String... strings) {
      boolean rc = false;

      if (!isRunning) {
        isRunning = true;
        //
        rc = true;
      }

      return rc;
    }

    @Override
    protected void onPostExecute(final Boolean result) {
      if (progressDialog != null) {
        progressDialog.cancel();
      }
      progressDialog = null;

      //    
    }
  }

  private class MyOnClickListener implements OnClickListener {

    private MyContainer container; 

    public MyOnClickListener(final MyContainer container) {
      this.container = container;
    }

    public void onClick(final View view) {
      if (container != null) {
        new MyAsyncTask().execute(container.getUrl());
      }
  }

  private String                 appName = "";
  private ArrayList<MyContainer> containers;
  private Context                context;
  private boolean                isRunning;
  private int                    layout;
  private MyProgressDialog       progressDialog;
  private Resources              resources;

  public MyAdapter(final Context context, final int layout, final ArrayList<MyContainer> containers, final long link_id) {
    super(context, layout, containers);

    this.context = context;
    this.layout = layout;
    this.containers = containers;

    resources = context.getResources();
    appName = resources.getString(R.string.txt_appname);
  }

  @Override
  public View getView(final int position, final View contentView, final ViewGroup viewGroup) {
    //
  }
}

Thanks in advance.

EDIT: Using the instance variable context from the adapter worked after cleaning the project. Arg! Thanks for your answers.

  • 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-24T21:28:38+00:00Added an answer on May 24, 2026 at 9:28 pm

    Hi 😀 well if you see your constructor of adapter

    public MyAdapter(final Context context, final int layout, final ArrayList<MyContainer> containers, final long link_id) {
        super(context, layout, containers);
    
        this.context = context;
    

    you pass context so in side of adapter you use context 😀 to build progress dialog

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

Sidebar

Related Questions

I am generating a listview as follows: setListAdapter(new ArrayAdapter<String>(this, R.layout.row, fileListS)); in which row
Use case: user clicks the link on a webpage - boom! load of files
I have a ListView that I want to use with an ArrayAdapter to add
I'm trying to display separate items in a list row. So i use 4
I have in my app a ListView with adapter , I use this to
I have a listview, with around 200 items, I have implemented a custom ArrayAdapter
I have a ListView that is populated with 50 items. This is the xml
I'm trying to use a ListView which is just like on this page: http://developer.android.com/resources/tutorials/views/hello-listview.html
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move
use this website a lot but first time posting. My program creates a number

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.