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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:07:40+00:00 2026-06-06T05:07:40+00:00

I am new to programing and I have some difficulties getting AlertDialog working. I

  • 0

I am new to programing and I have some difficulties getting AlertDialog working. I have six buttons displayed and I want to add alert dialog when sixth button is clicked. But I get an error saying “The constructor AlertDialog.Builder(LayoutOne, int) is undefined”. Can anyone help me?

Thank you!

public class LayoutOne extends Fragment implements OnClickListener {

    public static Fragment newInstance(Context context) {
        LayoutOne f = new LayoutOne();

    return f;
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater
            .inflate(R.layout.layout_one, null);
    ((Button) root.findViewById(R.id.drink)).setOnClickListener(this);
    ((Button) root.findViewById(R.id.sleep)).setOnClickListener(this);
    ((Button) root.findViewById(R.id.food)).setOnClickListener(this);
    ((Button) root.findViewById(R.id.events)).setOnClickListener(this);
    ((Button) root.findViewById(R.id.beach)).setOnClickListener(this);
    ((Button) root.findViewById(R.id.map)).setOnClickListener(this);

    return root;
}

public void onClick(View v) {
    // TODO Auto-generated method stub
    Button tmp = (Button) v;
    Button map = (Button) v;
    if (tmp.getId() == R.id.drink) {
        startActivity(new Intent("com.creatriks.zrce.DRINK"));
    } 
        if (tmp.getId() == R.id.sleep) {
            startActivity(new Intent("com.creatriks.zrce.SLEEP"));
        } 
            if (tmp.getId() == R.id.food) {
                startActivity(new Intent("com.creatriks.zrce.FOOD"));
            }


                if (tmp.getId() == R.id.events) {
                    startActivity(new Intent("com.creatriks.zrce.EVENTS"));
                } 
                    if (tmp.getId() == R.id.beach) {
                        startActivity(new Intent("com.creatriks.zrce.BEACH"));
                    }

                        if (map.getId() == R.id.map) {



                            AlertDialog alert = new AlertDialog.Builder(LayoutOne.this, AlertDialog.THEME_HOLO_LIGHT).create();
                            alert.setTitle("Options");
                            alert.setMessage("Choose an action");

                            startActivity(new Intent("com.creatriks.zrce.MAP"));



                }
            }

}

  • 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-06T05:07:42+00:00Added an answer on June 6, 2026 at 5:07 am

    Use getActivity() which returns the activity associated with a fragment.

    Change this

    AlertDialog alert = new AlertDialog.Builder(LayoutOne.this, AlertDialog.THEME_HOLO_LIGHT).create();
    

    To this

    AlertDialog alert = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_LIGHT).create();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a new visual basic learner and I already have some difficulties in
I'm new to concurrent programing and have been working on code which has a
I have some problem in matlab since I was new in this programming language.
I'm new to PHP programming and have poor knowledge about it, but I want
I am new to c++ programming and I have a basic issue, I want
I'm new with programing and my question is now, how i can close some
I'm new to funcctional programming and have some questions regarding coding style and debugging.
I'm fairly new to C programming and having some difficulties wrapping my brain around
I'm fairly new to OpenGL, and I seem to be experiencing some difficulties. I've
I'm new to Python (relatively new to programing in general) and I have created

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.