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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:35:29+00:00 2026-05-24T08:35:29+00:00

For some reasons I can’t use xml layout files. But I need to create

  • 0

For some reasons I can’t use xml layout files.

But I need to create a tablet android app.

I decided to use fragments.

I want to create the same layout that this xml generates:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent" android:layout_height="fill_parent">

    <fragment class="com.example.ItemsList"
            android:id="@+id/items_list" android:layout_weight="1"
            android:layout_width="0dp" android:layout_height="fill_parent" />

    <FrameLayout android:id="@+id/item_details" android:layout_weight="1"
            android:layout_width="0dp" android:layout_height="fill_parent"
            android:background="?android:attr/detailsElementBackground" />

</LinearLayout>

But I have problems with adding fragments to my linearLayout:

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(createUI());
    }

    private View createUI() {
        LinearLayout layout = new LinearLayout(this);

        layout.setOrientation(LinearLayout.HORIZONTAL);
        layout.setLayoutParams(new LinearLayout.LayoutParams(AbsListView.LayoutParams.FILL_PARENT, AbsListView.LayoutParams.FILL_PARENT));
        layout.setId(0x101);
        {
            FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            fragmentTransaction.add(0x101, new ItemsList());
            fragmentTransaction.add(0x101, new ItemDetails());
            fragmentTransaction.commit();
        }
        return layout;
    }

Actually I can’t even create LinearLayout with two identical fragments:

            ...
            fragmentTransaction.add(0x101, new ItemsList());
            fragmentTransaction.add(0x101, new ItemsList());
            ...

Please help

Btw I can’t figure out why do we need to declare “FrameLayout” for itemDetails Fragment but “fragment” is enough for itemsList ListFragment?

UPD:

To do so one should just add third param:

            ...
            fragmentTransaction.add(0x101, new ItemsList(), "uniqueTag1");
            fragmentTransaction.add(0x101, new ItemsList(), "uniqueTag2");
            ...

Default value for the tag parameter is null, so I was trying to create two different elements with identical ids. Thanks to p-lo for his comment.

  • 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-24T08:35:29+00:00Added an answer on May 24, 2026 at 8:35 am

    I’ve found the solution.

    (the better way was added to the question. Thanks, p-lo)

    If you want to place more than one fragment on activity you should create layouts for each fragment:

        private View createUI() {
            LinearLayout layout = new LinearLayout(this);
    
            layout.setOrientation(LinearLayout.HORIZONTAL);
            layout.setLayoutParams(new LinearLayout.LayoutParams(AbsListView.LayoutParams.FILL_PARENT, AbsListView.LayoutParams.FILL_PARENT));
    
    
            LinearLayout innerLayout1 = new LinearLayout(this);
            innerLayout1.setLayoutParams(new LinearLayout.LayoutParams(300, ViewGroup.LayoutParams.FILL_PARENT));
            innerLayout1.setId(ITEMS_LIST_ID);
            {
                FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
                fragmentTransaction.add(ITEMS_LIST_ID, new ItemsList());
                fragmentTransaction.commit();
            }
            layout.addView(innerLayout1);
    
            LinearLayout innerLayout2 = new LinearLayout(this);
            innerLayout2.setLayoutParams(new LinearLayout.LayoutParams(300, ViewGroup.LayoutParams.FILL_PARENT));
            innerLayout2.setId(ITEM_DETAILS_ID);
            {
                FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
                fragmentTransaction.add(ITEM_DETAILS_ID, new ItemDetails());
                fragmentTransaction.commit();
            }
            layout.addView(innerLayout2);
    
            return layout;
    
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For a number of reasons, the canonical source of some files I have can't
Hi every one for some reasons i can't use shake API , so iam
I read here some reasons to use constraints instead of triggers. But I have
I use (File System Based) static html files for caching, for some reasons i
I have some C++ code written in C-style. For some reasons I can't use
For some reasons I have to use WebView in my Android application and part
For some reason I can't use runat=server as an attribute for the input tag
I know PHP 5 already supports SQLite but for some reason I can't get
An easy problem, but for some reason I just can't figure this out today.
I am using Tm2. For some reasons,I disabled a bundle with Edit with Bundles,but

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.