-1

The following code does not make the popupWindow popup, most of the things I tried to make it work make it crash, some of them are commented, the rest just doesn't make the cut. Any leads?

// Popup the login
private void loginPopup(){

    // Get the contents
    RelativeLayout loginLayout = (RelativeLayout) findViewById(R.id.login_popup_layout);
    EditText usernameTxt = (EditText) findViewById(R.id.login_popup_username);
    EditText passwordTxt = (EditText) findViewById(R.id.login_popup_password);
    Button registerBtn = (Button) findViewById(R.id.login_popup_register);
    Button loginBtn = (Button) findViewById(R.id.login_popup_login);
    Button GloginBtn = (Button) findViewById(R.id.login_popup_G);
    Button FBloginBtn = (Button) findViewById(R.id.login_popup_FB);

    //loginLayout.addView(usernameTxt);

    // Popup the login menu
    //View popupView = getLayoutInflater().inflate(R.layout.login_popup_layout, null);
    PopupWindow loginPopup;
    loginPopup = new PopupWindow(loginLayout, 100, 100);// The last true is to make it focusable
    loginPopup.setWindowLayoutMode(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
    //loginPopup.setContentView(loginLayout);

    // Center the popup and display it.
    Display display = getWindowManager().getDefaultDisplay();
    Point size=new Point();
    display.getSize(size);
    loginPopup.showAtLocation((RelativeLayout)findViewById(R.id.displayLayout), Gravity.NO_GRAVITY, 50,50 );//(size.x/2)-loginPopup.getWidth()/2 , (size.y/2)-loginPopup.getHeight()/2 );}
Nic Szerman
  • 1,834
  • 18
  • 25
  • new PopupWindow(view, 100, 100) : view should be inflated (like you did in the line above, getLayoutInflater()... ) . You can't use content views that already belong to another layout. – natario Aug 15 '15 at 17:11

1 Answers1

0

I was using it wrongly, my idea of a PopupWindow wasn't a window that pops out of a view, I was thinking of a whole window that covered a big portion of the screen that had a separated layout with its's own classes and etcetera... In the end I made a new activity, with custom width and height, and made the black area, that wasn't covered by the activity, transparent. It seems that this is the correct implementation. In the code attached, the window didn't popup because I didn't inflate it.

Nic Szerman
  • 1,834
  • 18
  • 25