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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:04:08+00:00 2026-05-31T03:04:08+00:00

I’m new to Android development and am confused about how to accomplish what I’m

  • 0

I’m new to Android development and am confused about how to accomplish what I’m trying to do. I’ve done some reading and learning about fragments so I can share layout and code between various screen size designs. I’ve got a couple of fragments created and have used them successfully. But I’ve got a situation where I want to show a fragment in a normal activity on the phone, but want to show the fragment in a PopupWindow (or something similar if there’s a better choice) on a tablet.

I’ve managed to figure out how to inflate the fragment and display it in a PopupWindow when a button is clicked. My code looks like this:

public void onClick(View v) {
    LayoutInflater inflater = (LayoutInflater) BrowsingActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View popupLayout = inflater.inflate(R.layout.serverconnection_fragment, null, false);
    connectionListPopup = new PopupWindow(popupLayout, 300, 470, true);
    connectionListPopup.showAtLocation(BrowsingActivity.this.findViewById(R.id.connectionListImage), Gravity.CENTER, 0, 0);
}

The popup appears and contains the UI described in serverconnection_fragment.xml. The problem is that by creating it this way, the Fragment class ServerConnectionFragment.java is never instantiated so there are no items in the list in my UI, no listeners on buttons, and so on. It seems like there should be a way for me to instantiate the java class, have it inflate the fragment normally and attach event listeners, then pass the view created there into the PopupWindow constructor, but I can’t figure out how. Can anyone help me out?

FYI, I’m building this for Android 2.1 using the Android-support-v4.jar file for the Fragment classes.

  • 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-05-31T03:04:10+00:00Added an answer on May 31, 2026 at 3:04 am

    Inflating the layout directly will not cause it it to instantiate the fragment; Android would just consider it a mere coincidence that both the fragment and the activity are trying to refer to the same layout file.

    Ordinarily, you would use FragmentManager.add(int,Fragment) to add a fragment to a layout. However, the container id that you specify has to be part of the layout of the current Activity, and this is not the case with a PopupWindow. Instead, you would have to add the fragment to the fragment manager without specifying a container, and then sometime later in the fragment (e.g. onStart()) you can show a PopupWindow. This is precisely how DialogFragment works, and since there is already lots of support for it, I would suggest you switch to using a DialogFragment instead.

    With your Fragment code, simply extend DialogFragment instead of Fragment, and use DialogFragment.show(FragmentManager,String) to display it. You can get rid of the default border by calling setStyle(DialogFragment.STYLE_NO_FRAME, getTheme()) in the onCreate method. You can still add this Fragment to a layout (as you say, on a phone you do not want it to be shown as a popup) and it will work as how you expect.

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

Sidebar

Related Questions

I'm learning Android development and I'm a bit confused about how Android manages killing
I'm reading Beginning Android Application Development by Wei-Mung Lee. I'm confused about custom actions
I'm pretty new to learning about java and android development; so please help me
I am new to android development . I'm trying to download and run the
I'm new to Android development. My OS is WinXP. I'm trying to install two
I'm quite new to Android development. My understanding is that you can create several
I'm new to Android development and I'm currently going through some tutorials. When I
I'm very new to Android development and just started to study. What I'm trying
I am new to android development and I have a question about the insert
Im new to android development. Now im trying to use sqlite db. I 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.