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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:45:49+00:00 2026-06-15T21:45:49+00:00

i have created a button and set onClicklistener on it as well but i

  • 0

i have created a button and set onClicklistener on it as well but i can’t get it to open a popup. i have coded the xml and java code of it which can be seen below. When i click on it it clicks but doesn’t do anything.

xml code for the popup

    <?xml version="1.0" encoding="UTF-8"?>
    <LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width = "wrap_content"
android:layout_height = "wrap_content"
android:id = "@+id/popup"
android:orientation = "vertical">

<TextView 
    android:id = "@+id/popUpTitle"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:text = "@string/popup" />

<TextView 
    android:id = "@+id/popUpContent"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:text = "@string/popcontent"
    android:layout_marginBottom="47dp" />

<Button
    android:id="@+id/popUpButtonClose"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/close" />

java code for button to create a popup when clicked

    public void onClick(View arg0) {
    // TODO Auto-generated method stub
    switch(arg0.getId())
    {
        case R.id.buttonCreate:
            Intent i = new Intent(CreateQuestions.this, UploadQuestions.class);
            startActivity(i);
            break;

        case R.id.buttonStartQuiz:
            if (p2 != null)
            {
                showPopup(CreateQuestions.this, p2);
            }

}

method to create the popup

    //method that displays the pop up
}
private void showPopup(final CreateQuestions createQuestions1, Point p2) {
    // TODO Auto-generated method stub
    int popupWidth = 200;
    int popupHeight = 150;

    LinearLayout viewGroup = (LinearLayout) createQuestions1.findViewById (R.id.popup);
    LayoutInflater layoutInflater  = (LayoutInflater) createQuestions1.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup, viewGroup);

    //method to create the popup
    final PopupWindow popupWindow = new PopupWindow(createQuestions1);
    popupWindow.setContentView(layout);
    popupWindow.setWidth(popupWidth);
    popupWindow.setHeight(popupHeight);
    popupWindow.setFocusable(true);

    //some offseta to align the pop up  relative to the button's positions
    int OFFSET_X = 30;
    int OFFSET_Y = 30;

    //clear the default background
    popupWindow.setBackgroundDrawable(new BitmapDrawable());

    //displaying the pop up at the specified location and offsets
    popupWindow.showAtLocation(layout, Gravity.NO_GRAVITY, p2.x + OFFSET_X, p2.y + OFFSET_Y);

    //getting the reference to Close button and close the popup when clicked.
    close = (Button) layout.findViewById(R.id.popUpButtonClose);
    close.setOnClickListener(new OnClickListener(){

        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            popupWindow.dismiss();
        }


    });


    }

Any guidance help and tip would be really appreciated.

  • 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-15T21:45:50+00:00Added an answer on June 15, 2026 at 9:45 pm

    hummmm. . . .
    It looks like you dont have put the clickListener for the button.

    Have you put this code on onCreate ??

    buttonStartQuiz.setOnClickListener(this);
    

    or

    Also check for the value of p2 before below code

    if (p2 != null)
    

    It seems like you are not initialize the variable. So please check it.

    If not then put it and see. If still not solve your issue then let me know.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a button in my screen's XML like this: <Button android:text=Lets Get
I have created a button in my Android application & I tried to set
I have butons which are created dynamically, each button has an id set in
I have a RelativeLayout completely created within java, not using xml layout. I have
I have a problem I can't set the text of a button during a
I have created button 2 below: <input id=Button1 type=button value=Stop onclick=alert('hello world');/> <input id=Button2
I have created a button CSS class that uses background images with different positions
I have created a button. So when I click the button it gives me
I have created a button which I want to expand/contract. I found a way
I have a Main class and a HelloWorld class. I have created a button

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.