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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:09:01+00:00 2026-06-12T19:09:01+00:00

I’m trying to do dynamic fragment layouts. I’m using 2 xml files : one

  • 0

I’m trying to do dynamic fragment layouts.
I’m using 2 xml files : one is the main_layout and the other one is the fragment1.

I used the Log.i so I can know where my program is crashing, but it cites that is running the code fine but it doesn’t appear the fragment1 on the main_layout.

Here is my code:

main_layout.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:id="@+id/testFragment"
        android:visibility="gone" >
</FrameLayout>

fragmenta.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="vertical"
    android:id="@+id/fragmenta" 
    android:background="#F000F0">

    <TextView
        android:id="@+id/fragmentatext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Fragmenta 1" />

</LinearLayout>

here is my Side_Fragment which extends SherlockFragment :

View view;
    private final String TAG = "Side_Fragment";
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {


            view = inflater.inflate(R.layout.fragmenta, container, false);
            Log.i(TAG,"fragment installed");
            return view;
    }
    @Override
    public void onAttach(Activity activity) {
        // TODO Auto-generated method stub
        super.onAttach(activity);
    }


}

and here is the main activity :

    private final String TAG = "Main Activity";
    FragmentManager fm = getSupportFragmentManager();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_layout);
        Log.i(TAG,"OnCreate");

        Button add = (Button) findViewById(R.id.button1);

        Log.i(TAG,"called FragmentManager");
    }



    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId())
        {
        case R.id.twitter:
            Log.i(TAG,"Twitter is clicked");
             // Check to see if the Fragment back stack has been populated // If not, create and populate the layout.
            Fragment detailsFragment = (Side_Fragment)fm.findFragmentById(R.id.fragmenta);
            Log.i(TAG,"called FragmentManager");
            if (detailsFragment == null) {
            Log.i(TAG,"pass ifstatment");
            FragmentTransaction ft = fm.beginTransaction(); 
            Log.i(TAG,"called FragmentTransaction");
            Side_Fragment test = new Side_Fragment();
            ft.add(R.id.testFragment,test);
            Log.i(TAG,"called add");
            ft.addToBackStack(null);
            ft.commit();
            Log.i(TAG,"called commit");
            getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
            }
            return true;
        case R.id.facebook:
            Log.i(TAG,"Facebook is clicked");
            return true;
        case R.id.refresh:
            Log.i(TAG,"Refresh is clicked");
            return true;
        default:
            return super.onOptionsItemSelected(item);
        }

    }




    @Override
    public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
        final MenuInflater inflater = getSupportMenuInflater();
        inflater.inflate(R.menu.main, menu);
        return true;
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        Log.i(TAG,"onPause");
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        Log.i(TAG,"onResume");
    }

    @Override
    protected void onStart() {
        // TODO Auto-generated method stub
        super.onStart();
        Log.i(TAG,"onStart");
    }

}
  • 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-12T19:09:02+00:00Added an answer on June 12, 2026 at 7:09 pm

    You’ve set your FrameLayout width a bit small: android:layout_width="0dp". That will make it impossible to see.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am reading a book about Javascript and jQuery and using one of the
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have thousands of HTML files to process using Groovy/Java and I need to
I'm making a simple page using Google Maps API 3. My first. One marker
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.