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

  • Home
  • SEARCH
  • 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 8009601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:29:49+00:00 2026-06-04T18:29:49+00:00

I have a tabHost based app, with fragments, It works fine if I use

  • 0

I have a tabHost based app, with fragments,
It works fine if I use my fragments with a LinearLayout

but I need to have a list on one of the tabs views [fragment]

but the app crashes because is not correctly inflated:
my class [tab view Fragment]:

public class Tab2Fragment extends Fragment { //primera pregunta, lo puedo hacer asi o con FragmentActivity
//public class Tab2Fragment extends ListFragment { //primera pregunta, lo puedo hacer asi o con FragmentActivity


    private FragmentManager fm;
    private ListFragment list;
    private List<Map<String, String>> listItems;
    private String[] froms;
    private int[] viewIds;

    /* (non-Javadoc)
     * @see android.support.v4.app.Fragment#onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle)
     */


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        if (container == null) {
            // We have different layouts, and in one of them this
            // fragment's containing frame doesn't exist.  The fragment
            // may still be created from its saved state, but there is
            // no reason to try to create its view hierarchy because it
            // won't be displayed.  Note this is not needed -- we could
            // just run the code below, where we would create and return
            // the view hierarchy; it would just never be used.
            return null;
        }
        return (LinearLayout)inflater.inflate(R.layout.tab_frag2_layout, container, false);
    }



}

my 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:background="#00FF00">

        <fragment
        android:name="android.support.v4.app.ListFragment"
        android:id="@+id/List"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

</LinearLayout>

the error:

05-31 22:39:58.412: E/AndroidRuntime(2796): FATAL EXCEPTION: main
05-31 22:39:58.412: E/AndroidRuntime(2796): android.view.InflateException: Binary XML file line #8: Error inflating class fragment
05-31 22:39:58.412: E/AndroidRuntime(2796):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
05-31 22:39:58.412: E/AndroidRuntime(2796):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
05-31 22:39:58.412: E/AndroidRuntime(2796):     at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
05-31 22:39:58.412: E/AndroidRuntime(2796):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
05-31 22:39:58.412: E/AndroidRuntime(2796):     at com.orchard.elasto.Tab2Fragment.onCreateView(Tab2Fragment.java:54)
05-31 22:39:58.412: E/AndroidRuntime(2796):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)

So, how to properly inflate the list?

should i do it with fragmentList, even when the tabHost is specting a Fragment?

public void onTabChanged(String tag) {
        TabInfo newTab = this.mapTabInfo.get(tag);
        if (mLastTab != newTab) {
            FragmentTransaction ft = this.getSupportFragmentManager().beginTransaction();
            if (mLastTab != null) {
                if (mLastTab.fragment != null) {
                    ft.detach(mLastTab.fragment);
                }
            }
            if (newTab != null) {
                if (newTab.fragment == null) {
                    newTab.fragment = Fragment.instantiate(this,
                            newTab.clss.getName(), newTab.args);
                    ft.add(R.id.realtabcontent, newTab.fragment, newTab.tag);
                } else {
                    ft.attach(newTab.fragment);
                }
            }

            mLastTab = newTab;
            ft.commit();
            this.getSupportFragmentManager().executePendingTransactions();
        }
    }

thanks a lot!!

  • 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-04T18:29:51+00:00Added an answer on June 4, 2026 at 6:29 pm

    Your problem is here:

       android:name="android.support.v4.app.ListFragment" 
    

    You are telling it that the class that runs that fragment is ListFragment.

    You need to change it to reference your class, and you need to make that class a ListFragment instead of a Fragment.

       android:name="your.package.name.Tab2Fragment" 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a TabHost with 2 Fragments, both lists. The onCreateContextMenu works fine for
I'm developing an app which contain TabHost ,in one of those tabs i have
I have a tabhost where I need to use onTabChanged listener, but it does
In my android app I have a Tabhost with a ListView as one of
I have problem with initializing TabHost. I need to have in View several Tabs
I have created a tab based app, in one of the tab, there is
I have some tabs based on layouts with their own xml description, but when
I have TabHost with three tabs. One of these tabs contains ListActivity. I want
I have a tabHost, with to tabs and an activity each one of them.
I need to have a TabHost consisting of two tabs where each tab represented

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.