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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:56:54+00:00 2026-06-16T23:56:54+00:00

I have implemented an Activity that hosts two fragments. I have one fragment on

  • 0

I have implemented an Activity that hosts two fragments. I have one fragment on the left and one on the right. The fragment on the left is a list of items to click. When you click on it inflates a new fragment on the right.

One item on the left list is supposed to inflate a different list on the right. I have it working good except when you click that item it inflates the list to cover the entire screen. And I only want it to cover the space on the right side of the screen.

Is there a way I can keep the fragment from covering the entire screen? All the others stay on the right side of the screen, its just this one that doesn’t. But this is the only one trying to inflate a ListView on the right side.

Here are the relevant methods of the ListFragemnt that is supposed to be on the right inflated on the right side:

public void onActivityCreated(Bundle inState) {
    super.onActivityCreated(inState);
    //setContentView(R.layout.results_list_activity);
    //mIntent = getIntent();
    mActivity = getActivity();
    mArrayListRecipe = generateList();

    ListView listView = (ListView) mActivity.findViewById(android.R.id.list);
    ArrayAdapter<Recipe> adapter = new ArrayAdapter<Recipe>(mActivity,
            android.R.layout.simple_list_item_1, mArrayListRecipe);

    listView.setAdapter(adapter);
    //listView.setOnItemClickListener((OnItemClickListener) this);
}

public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.results_list_activity, container, false);
    return layout;
}

And here is the XML layout that is inflated called results_list_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

<ListView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/list"
          android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/>

And here is the layout that contains the frame that I want this ListView placed in main_activity.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools" android:id="@+id/main_layout_land"
          android:layout_width="match_parent" android:layout_height="wrap_content"
          android:orientation="horizontal" android:layout_alignParentBottom="true">

<!-- Left side fragment -->
<fragment class="com.jasoncrosby.app.recipeorganizer.MainFragment" android:id="@+id/left_fragment"
              android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/>

<!-- Right side fragment -->
<FrameLayout android:id="@+id/right_fragment" android:layout_width="0dp" android:layout_height="match_parent"
                 android:layout_weight="1"/>
</LinearLayout>

EDIT:

The activity that loads the fragment is simple and only consists of a call to:

setContentView(R.layout.main_activity);

Here is MainFragment.java:

public class MainFragment extends ListFragment {

//*******
// Fields
//*******

    /** Indicated weather there is enough room on the screen to use 2 panes. */
    private boolean mDualPane;

    /** Indicates which item in the main list was clicked. */
    private int mCurCheckPosition = 0;

    /** The name of the save button. */
    private String mStringSaveItemName;

    /** The name of the search button. */
    private String mStringSearchItemName;

    /** The name of the browse button. */
    private String mStringBrowseItemName;

    /** The name of the random button. */
    private String mStringRandomItemName;

    /** The {@code Activity} associated with this {@code Fragment}. */
    private Activity mActivity;

//*************
// Constructors
//*************

/**
 * This constructor is only provided to avoid a compiler warning. It should not be used to crate a new
 * {@code MainFragment} object.
 */
public MainFragment(){}

/**
 * Used to create a new {@code MainFragment} object with the id.
 * 
 * @param id
 */
//public MainFragment(int id) {
    //mIntFragmentId = id;
    //mContext = context;
//}

//*******************
// Overridden methods
//*******************

@Override
public void onActivityCreated(Bundle savedState) {
    super.onActivityCreated(savedState);

    mActivity = getActivity();

    mStringSaveItemName = mActivity.getString(R.string.save_button);
    mStringSearchItemName = mActivity.getString(R.string.search_button);
    mStringBrowseItemName = mActivity.getString(R.string.browse_button);
    mStringRandomItemName = mActivity.getString(R.string.random_button);

    // Populate list with our static array of titles.
    setListAdapter(new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,
            new String[] {mStringSaveItemName, mStringSearchItemName, mStringBrowseItemName,
            mStringRandomItemName}));

    // Check to see if we have a frame in which to embed the details
    // fragment directly in the containing UI.
    View detailsFrame = mActivity.findViewById(R.id.right_fragment);
    mDualPane = detailsFrame != null && detailsFrame.getVisibility() == View.VISIBLE;

    if (mDualPane) {
        // In dual-pane mode, list view highlights selected item.
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        // Make sure our UI is in the correct state.
        showDetails(mCurCheckPosition);
    }
}

@Override
public void onListItemClick(ListView l, View v, int pos, long id) {
    showDetails(pos);
}

//****************
// Private methods
//****************

private void showDetails(int index) {
    mCurCheckPosition = index;

    if (mDualPane) {

        switch (mCurCheckPosition) {
            case 0  : inflateFirstUi(); break;
            case 1  : inflateSecondUi(); break;
            case 2  : inflateThirdUi(); break;
            case 3  : inflateFourthUi(); break;
            default : inflateFirstUi(); break;
        }

    } else {
        // Otherwise we need to launch a new activity to display
        // the dialog fragment with selected text.
        Intent intent = new Intent();
        //intent.setClass(getActivity(), DetailsActivity.class);
        intent.putExtra("index", index);
        startActivity(intent);
    }
}

private void inflateFirstUi() {
    SaveFragment details = new SaveFragment();

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.right_fragment, details);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();
}

private void inflateSecondUi() {
    SearchFragment details = new SearchFragment();

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.right_fragment, details);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();
}

private void inflateThirdUi() {
    ResultsListFragment details = new ResultsListFragment(Constants.BROWSE_REQUEST);

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.right_fragment, details);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();
}

private void inflateFourthUi() {
    ResultsListFragment details = new ResultsListFragment(Constants.RANDOM_REQUEST);

    FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.replace(R.id.right_fragment, details);
    ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
    ft.commit();
}
}

The problem is in the showDetails() method in the switch statement. Case 0 and case 1 work just fine and load in the pane I have on the right side of the screen. Case 3 is where I am running into this problem. It loads the UI but its covering the entire screen and not confined to the right side in the pane.

  • 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-16T23:56:55+00:00Added an answer on June 16, 2026 at 11:56 pm

    Ok I have the problem solved. In my onActivityCreated() method I made a call to:

    listView.setAdapter(adapter);
    

    I went back and compared the fragments that are working with this one that is not working. I found in the ones that work I called this instead:

    setListAdapter(adapter);
    

    I changed the non working fragment to call setListAdatpter(adapter) and not listView.setAdapter(adapter). And now the fragment is being shown in the right side of the screen like it should be. Thanks to everyone who helped and was looking into this.

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

Sidebar

Related Questions

I have implemented onRetainNonConfigurationInstance() on one of my Activity to handle android screen orientation.
I have implemented an activity that retrieves data from a web service and display
I have implemented a UIActivityIndicator that shows up in one part of my program
I have implemented an adapter for my ListView which extends BaseAdapter. My list items
I have implemented an activity that plays media from a URL in Android. In
I have two classes: An activity class that controls several widgets and then a
I have implemented a Java activity that displays a Google map view, and would
I have implemented a custom view within another activity into a XML layout. The
I have implemented Facebook into my app but now I find that whenever I
Currently I have a TabHost implemented with 3 tabs each containing a separate activity.

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.