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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:37:08+00:00 2026-06-14T22:37:08+00:00

I have a ListView and I populated it dinamically through an Adapter. Each row

  • 0

I have a ListView and I populated it dinamically through an Adapter. Each row of my ListView have a button and I want to show a DialogBox when it is clicked. However I dunno how to pass the context to my AlertDialog, so it can show up on my activity. What I have is something like this:

....//ADAPTER
public View getView(int position, View view, ViewGroup parent) {
   ....
   pay.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            AlertDialog.Builder ad = new AlertDialog.Builder();  
            ad.setMessage("Are you sure?");  
            ad.setPositiveButton("Ok", new DialogInterface.OnClickListener() {  
                public void onClick(DialogInterface dialog, int which) {  
                    dialog.dismiss();                      
                }  
            });  
            AlertDialog dialog = ad.create()();
            dialog.show();
        }
    });
 ....
 }

I guess I must add some kind of listener at the activity which extends my ListView but Im lost on how do it and the documentation is way too large, couldn’t find the solution.

  • 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-14T22:37:09+00:00Added an answer on June 14, 2026 at 10:37 pm

    You can pass an activity context to your adapter in a constructor and then use it in your adapter class:

    public class MyAdapter {
        Context context;
    
        public MyAdapter(Context context, ... ) { 
            this.context = context;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView that is populated using an XML file. However, I want
I have a ListView that's populated from a SimpleCursorAdapter each row containing 3 different
I have a ListView in a ListActivity populated with strings. However, only the text-part
I want to create a listview populated with items I have transferred to this
I have a populated ListView with custom adapter and my objective is to download
I have a ListView that is being populated with a custom adapter. I have
I have a ListView that is being populated with a custom adapter. I'd like
I have a ListView which is populated using a SimpleCursorAdapter. The row layout is
I have a ListView which is populated using a web service. I want to
I have a ListView that is fed by an SQLiteDB. On each row returned,

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.