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

The Archive Base Latest Questions

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

In my parent Activity i’ve a button, when i click on it shows PopUpWindow

  • 0

In my parent Activity i’ve a button, when i click on it shows PopUpWindow with 2 ImageButton.. When this PopUpWindow exists ‘m unable click my parent activity Button.. Here is my code, is there any problem in it..

public class PopUpExample extends Activity {

    Button but;
    LinearLayout mainLayout;
    PopupWindow popUp;
    boolean click = true;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);      

        mainLayout = (LinearLayout) findViewById(R.id.main_layout);     
        but = (Button) findViewById(R.id.main_btn);     

        but.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                View popView;

                if(click){
                    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
                    popUp = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false),100, 50, true);
                    popUp.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
                    popUp.update();
                    click = false;

                    popView = popUp.getContentView();

                    ImageButton call = (ImageButton) popView.findViewById(R.id.call_btn);   

                    call.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {                           
                            Toast.makeText(PopUpExample.this, "Calling...", Toast.LENGTH_SHORT).show();
                        }
                    });

                    ImageButton sms = (ImageButton) popView.findViewById(R.id.sms_btn); 

                    sms.setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {                           
                            Toast.makeText(PopUpExample.this, "Sms...", Toast.LENGTH_SHORT).show();
                        }
                    });

                }else{
                    popUp.dismiss();
                    click = true;
                }                       

            }    
        });
    }    
}
  • 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-16T03:34:00+00:00Added an answer on June 16, 2026 at 3:34 am

    The popview when created takes away focus from the mainView so the user is not able to click the elements which are on the main view.

    To click on the main view one need to dismiss popview first.

    With respect to the above theory in your code You trying to dismiss popview by clicking on the button which is at main activity which is not possible.

    Below code has the changes which you need to incorporate in your above code

    public class PopUpExample extends Activity {    
        Button but;
        LinearLayout mainLayout;
        PopupWindow popUp;
        //boolean click = true;
        View popView;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            mainLayout = (LinearLayout) findViewById(R.id.main_layout);     
            but = (Button) findViewById(R.id.main_btn);     
    
            but.setOnClickListener(new OnClickListener() {
    
                public void onClick(View v) {
    
                    // if(click){
                        LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
                        popUp = new PopupWindow(inflater.inflate(R.layout.popup_example, null, false),100, 50, true);
                        popUp.showAtLocation(mainLayout, Gravity.CENTER, 0, 0);
                        popUp.update();
                        //click = false;
    
                        popView = popUp.getContentView();
    
                        ImageButton call = (ImageButton)popView.findViewById(R.id.call_btn);   
    
                        call.setOnClickListener(new OnClickListener() {
    
                            public void onClick(View v) {                           
                                Toast.makeText(MainActivity.this, "Calling...", Toast.LENGTH_SHORT).show();
                                popUp.dismiss();
                            }
                        });
    
                        ImageButton sms = (ImageButton)popView.findViewById(R.id.sms_btn); 
    
                        sms.setOnClickListener(new OnClickListener() {
    
                            public void onClick(View v) {                           
                                Toast.makeText(MainActivity.this, "Sms...", Toast.LENGTH_SHORT).show();
                                popUp.dismiss();
                            }
                        });
    
                   //}else{
                       // popUp.dismiss();
                     // click = true;
                   // }                       
    
                }    
            });
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried using this code to start multiple Activities from a parent activity: for
My requirement is One activity is calling another activity.When I click the radio button
If an activity calls it parent activity by startActivity(intent) // Here intent is parent
I am creating one parent Activity(Class) and then want to extends this class to
I have parent Activity , where I have some code written in onResume() of
i am trying to pass an arraylist back to my parent activity Here is
How I can get name of parent activity in child activity. I have two
So I have a fairly complex activity the parent being a linearlayout with a
Class parent { protected void myMethod() { if(someCodition) { //return this as well as
I have a Parent activity which is sending data to child activity but the

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.