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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:43:22+00:00 2026-05-27T19:43:22+00:00

I’m trying to implement a simple fragment in android. I’ve tried various approaches and

  • 0

I’m trying to implement a simple fragment in android.

I’ve tried various approaches and the only time I don’t get an error is when I remove the fragment from the layout altogether. Other than that, I’ve removed inflate and tried to create a layout manually and that didn’t work either.

Only removing the fragment from the layout seems to make the application load, no matter what else I do, the application crashes.

I keep getting the following error:

12-29 04:52:07.493: E/AndroidRuntime(11717):
java.lang.RuntimeException: Unable to resume activity
{com.p5sys.android.jump/com.p5sys.android.jump.lib.activities.DisplayContactList}:
android.view.InflateException: Binary XML file line #9: Error
inflating class fragment

I also get the following error after the above errors stacktrace (just sharing incase it helps).

12-29 04:52:07.493: E/AndroidRuntime(11717): Caused by:
java.lang.IllegalArgumentException: Binary XML file line #9: Duplicate
id 0x7f090023, tag null, or parent id 0x0 with another fragment for
com.p5sys.android.jump.lib.fragment.HeaderFragment

My layout contact_layout.xml is a LinearLayout with a fragment and ListView in it:

<fragment
    android:id="@+id/headerFragment"
    android:layout_width="0dp"
    android:layout_height="fill_parent"
    class="com.p5sys.android.jump.lib.fragment.HeaderFragment" />

<ListView
    android:id="@+id/contactList"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:background="@color/transparent"
    android:cacheColorHint="#00000000" >
</ListView>

The fragment layout header_fragment.xml is:

<TableRow>
    <ImageButton
        android:id="@+id/btnSettings"
        android:gravity="left"
        android:hint="@string/label_settings"
        android:onClick="btnAction_launchSettings"
        android:padding="3dip"
        android:src="@drawable/ic_menu_add" />

    <TextView
        android:id="@+id/headerText"
        android:gravity="center"
        android:height="50dip"
        android:padding="3dip"
        android:textSize="20sp"
        android:textStyle="bold"
        android:text="Blank" />

    <ImageButton
        android:id="@+id/btnAdd"
        android:background="@drawable/disconnectbutton"
        android:gravity="right"
        android:hint="@string/label_add"
        android:onClick="btnAction_launchAddNew"
        android:padding="3dip"
        android:src="@drawable/ic_menu_add" />
</TableRow>

My Fragment class:

package com.p5sys.android.jump.lib.fragment;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.p5sys.android.jump.lib.R;
/***
 * Fragment
 * @author Ali
 *
 */
public class HeaderFragment extends Fragment {

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // inflate layout
        return inflater.inflate(R.layout.header_fragment, container, false);
//      LinearLayout ll = new LinearLayout(getActivity());
//      TextView tv = new TextView(getActivity());
//      tv.setText("hello world");
//      ll.addView(tv);
//      return ll;
    }
}

In my Activity I’m not doing anything special, I’ve tried using regular Activity as well as FragmentActivity and I’ve gotten the same problem.

Any help would be much appreciated.

  • 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-27T19:43:23+00:00Added an answer on May 27, 2026 at 7:43 pm

    I never had much luck with this approach myself. Plus, you’re going to have to do it differently anyway if you want the possibility to instantiate many types of fragments in the same place within the layout, or swipe through many instances of Fragments with your finger (via ViewPager), etc.

    So here’s what I do: 1) Use a FrameLayout to reserve space for the Fragment.

    <FrameLayout
        android:id="@+id/where_i_want_my_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    

    2) Instantiate the Fragment with the following Java code:

    FragmentManager fragMgr = getFragmentManager();
    FragmentTransaction xact = fragMgr.beginTransaction();
    if (null == fragMgr.findFragmentByTag(myFragTag)) {
        xact.add(R.id.where_i_want_my_fragment, MyDerivedFragment.newInstance(), myFragTag).commit();
    }
    

    myFragTag is a String value you need to come up with. It’s the tag name you want to assign to the Fragment instance, similar to the “id” attribute in HTML. If you only have one Fragment instance, then you can call it anything you want; otherwise it’s best to designate the tag name as something related to what that specific instance is appearing in.

    Don’t forget the commit() part at the very end, otherwise it won’t work!

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

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Seemingly simple, but I cannot find anything relevant on the web. What is the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.