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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:12:41+00:00 2026-05-27T12:12:41+00:00

In my application I am trying to use a ListView inside a PopupDialog .

  • 0

In my application I am trying to use a ListView inside a PopupDialog. This is done inside of an AsyncTask. I think the issue lies somewhere between the onPreExecute and onPostExecute…..everything is returning correctly, but the list = null after I use findViewById(). I can’t figure out why……Note, the AsyncTask and Adapter are both inner classes.

    protected void onPreExecute() {
        AlertDialog.Builder alert = new AlertDialog.Builder(CreateNewReport.this);
        LayoutInflater inflater = LayoutInflater.from(CreateNewReport.this);
        popupView = inflater.inflate(R.layout.add_expenses, null);

        alert.setTitle("Add Expenses").setView(popupView);

        alert.setNeutralButton("Save", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {

            }
        });

        alert.show();
    }

    protected void onPostExecute(List<Expense> expenses){
        availableExpenses = expenses;

        // create list adapter for available expenses
        ArrayAdapter<Expense> adapter = new ArrayAdapter<Expense>(CreateNewReport.this,
                android.R.layout.simple_list_item_1, expenses);

        // get a reference to the list
        final ListView list = (ListView) findViewById(R.id.listViewAvailableExpenses);

        // set the list adapter
        list.setAdapter(adapter);

        // find widgets
        final ProgressBar progress = (ProgressBar) findViewById(R.id.loading_expenses);
        final LinearLayout listLayout = (LinearLayout) findViewById(R.id.available_expenses);
        final LinearLayout progressContainer = (LinearLayout) findViewById(R.id.available_expenses_loading);

        // change visibility as needed
        progressContainer.setVisibility(View.INVISIBLE);
        progress.setVisibility(View.INVISIBLE);
        listLayout.setVisibility(View.VISIBLE);
    }

XML for the popup box

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <ProgressBar
         android:id="@+id/loading_expenses"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         style="@android:style/Widget.ProgressBar.Large"
         android:layout_centerInParent="true"
         />
        <ListView
            android:id="@+id/listViewAvailableExpenses"
            style="@style/Container"
            android:cacheColorHint="#00000000"
            />
</RelativeLayout>
  • 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-27T12:12:42+00:00Added an answer on May 27, 2026 at 12:12 pm

    That’s because the findViewById() call is looking for your list inside the Activity (it’s a method of the Activity instance), but your list is inside the dialog. Instead, you need to save a reference to the dialog and then do theDialog.findViewById(R.id.ListNote):

    //PreExecute
    theDialog = alert.create(); //theDialog is an instance variable of the asynctask
    theDialog.show();
    
    
    //PostExecute
    final ListView list = (ListView) theDialog.findViewById(R.id.ListNote);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my ajax application I'm trying to use a recursive function inside of which
I have a Spring MVC application trying to use a rich domain model, with
I have a C++ library and a C++ application trying to use functions and
I'm writing an ASP.NET MVC application and trying to use a RESX file to
I am trying to use FIX::Application along with SessionSettings. The Fix server I am
I am trying to use log4net in an ASP.NET application with Visual Studio 2005.
I'm trying to use the FolderBrowserDialog from my WPF application - nothing fancy. I
I am trying to use the .NET Backgroundworker Object in an application I am
I am trying to use Aptana to build an IPhone web application. I've never
I am trying to use Spring.NET with a C# application to populate a parameter

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.