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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T03:16:20+00:00 2026-06-11T03:16:20+00:00

I am trying to add Alert Builder Inside a BaseAdapter under button clicked. Here

  • 0

I am trying to add Alert Builder Inside a BaseAdapter under button clicked.
Here is my code

 Button btn=(Button)vi.findViewById(R.id.btnAdd);
 btn.setOnClickListener(new OnClickListener(){

                             AlertDialog.Builder dialogBox=new AlertDialog.Builder(this);
                 dialogBox.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
                       public void onClick(DialogInterface dialog, int which) {
                          String facebookFriendName = friendsName.getText().toString();
                                String FACEBOOKID = FBID;
                               Log.i("AKO SI: ", ""+facebookFriendName + FACEBOOKID);
                       }
                    });
                    dialogBox.setNegativeButton("No", new DialogInterface.OnClickListener(){

                           public void onClick(DialogInterface dialog, int which) {

                           }
                        });
                    dialogBox.show();     

Now I am getting an error on this part alert_box.show();

What seems to be the problem?

EDIT
based on your suggestion and comments I change my code above
and add a getter and setter on my Activity

private Context context;  
/////////
            public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

Under my activity class under binding

    adapter2 =new LazyAdapterGetFriends(this, songsList);   
             adapter2.getContext();    
             list.setAdapter(adapter2);

But I am still getting an error saying:

*09-11 13:48:49.298: E/AndroidRuntime(1226):    at com.fb.connect.LazyAdapterGetFriends$1.onClick(LazyAdapterGetFriends.java:95)

*pointing at AlertDialog.Builder dialogBox=new AlertDialog.Builder(context);
  • 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-11T03:16:21+00:00Added an answer on June 11, 2026 at 3:16 am

    try this

      Button btn=(Button)vi.findViewById(R.id.btnAdd);
      btn.setOnClickListener(new OnClickListener(){
    
        public void onClick(View arg0) {
                // TODO Auto-generated method stub
    
    
            AlertDialog.Builder ab=new AlertDialog.Builder(MainActivity.this);
            ab.setPositiveButton("Yes", new DialogInterface.OnClickListener(){
               @Override 
               public void onClick(DialogInterface dialog, int which) {
                  String facebookFriendName = friendsName.getText().toString();
                        String FACEBOOKID = FBID;
                       Log.i("AKO SI: ", ""+facebookFriendName + FACEBOOKID);
               }
            });
            ab.setNegativeButton("No", new DialogInterface.OnClickListener(){
                   @Override 
                   public void onClick(DialogInterface dialog, int which) {
    
                   }
                });
            ab.show();                       
        }                
    });
    

    hope help

    EDIT

    try this.

    AlertDialogs can only be created using Activity contexts, so getApplicationContext() will not work. Instead, add the following global variable to your Activity file:

    Context mContext;
    

    And then add the following to your onCreate():

    mContext = this;
    

    Now, change:

    AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
    

    to

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying add picture boxes dynamically. My code is as PictureBox picture =
I'm trying to add a button onclick event to a button tag when I
I'm trying to add some functionality to our code base by using tied scalars.
I am trying to have a method in my code behind at runtime add
I'm trying to add an alert dialog within a method, but I'm getting an
I am trying to add alert for loging user using programming. It is giving
I'm trying to add support into showdown.js for code fencing, but I'm still sort
i am trying to add a button in the autocomple.js when no match if
I am currently trying to add to an object through a function. My code
I'm trying to add a proximity alert in my application but with variable radius.

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.