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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:15:28+00:00 2026-06-03T03:15:28+00:00

Without showing too much code: I have an Activity A. This Activity populates a

  • 0

Without showing too much code:

I have an Activity “A”. This Activity populates a ListView via a BaseAdapter,
the BaseAdapter‘s getView() sets an onClickListener() for an item in every row.

I want to show an AlertDialog in Activity “A” when the rows’ item is clicked.

  • 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-03T03:15:29+00:00Added an answer on June 3, 2026 at 3:15 am

    I don’t see where you encounter problems. If you have your BaseAdapter version in the Activity A then you could simply call(in the OnCLickListener for that row’s item that you set in the getView method of the BaseAdapter) a private method that you create in the A Activity:

    private void showADialog(int position) {
            new AlertDialog.Builder(this)
                    .setMessage("The clicked row is " + position)
                    .setPositiveButton("Ok?",
                            new DialogInterface.OnClickListener() {
    
                                @Override
                                public void onClick(DialogInterface dialog,
                                        int which) {
                                    dialog.dismiss();
                                }
    
                            }).show();
        }
    

    If your custom BaseAdapter isn’t in the same file as Activity A then you could use the Context that you passed to the BaseAdapter(if the code for your adapter is the one from your previous question, if not you should pass it in the constructor). You could then cast that Context to your activity and call the previous method showADialog(). Also when you set the listener you should pass the position as a tag so you can retrieve it in the OnCLickListener(otherwise you could get the wrong position as the views + listener get recycled):

    //...
    item.setTag(new Integer(position)); // or if you use a ViewHolder: holder.item bla.....
    item.setOnClickListener(new OnClickListener() {
       @Override
       public void onClick(View v) {
        Integer realPosition = (Integer) v.getTag();
        // Here show the dialog using one of the methods above.You either:        
        // showADialog(realPosition); // when the code for your custom BaseAdapter in in the same class as Activity A
        //((CallingAlertDialogBaseAdapter) context).showADialog(realPosition); // when the code for the custom BaseAdapter is in a separate file then Activity A
        //create directly an AlertDialog. For this you'll require a valid Context(from an  Activity(getApplicationCOntext() will NOT work). 
       //You have this context from the parameter that you pass in the constructor of your custom BaseAdapter(as you ussualy pass this in the Activity where you instantiate the adapter)
       }
    });
    //...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm going to try and explain this without showing any code because I don't
Or i have been building web pages for too long without a break or
OK...I've spent too much time floundering on this one, so I'm passing it on
in my code i need to run notification control without showing any form how
How can I pass a viewmodel to a view without the model's data showing
Without spending a long time reviewing the boost source code, could someone give me
I am trying to send a faceless email (sending an email without showing the
I have some inline links with icon showing on the left (padding + bacground),
I want to call google map intent without showing Complete Action Dialog? Is it
This is more of a theoretical question than code: What i did till now

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.