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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:19:18+00:00 2026-06-16T01:19:18+00:00

this is my app (with fragments): On the left side there is a ListView

  • 0

this is my app (with fragments):
On the left side there is a ListView where you can choose.
If you selected one the right side load a fragment and add Tabs to the ActionBar.
There is the code for that:

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.app.SherlockFragmentActivity;

public class SpieleUndTabelleFragment extends SherlockFragment
{       
    ViewPager mViewPager;
    TabsAdapter mTabsAdapter;

    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState)
    {
        ActionBar bar = getSherlockActivity().getSupportActionBar();
        bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        bar.setHomeButtonEnabled(true);

        mViewPager = new ViewPager(getSherlockActivity());
        mViewPager.setId(R.id.pager);

        mTabsAdapter = new TabsAdapter(getSherlockActivity(), mViewPager);

        mTabsAdapter.removeAllTabs();
        mTabsAdapter.addTab(bar.newTab().setText("Alle Spiele"), Spiele.class, null);
        mTabsAdapter.addTab(bar.newTab().setText("Tabelle"), Tabelle.class, null);

        return mViewPager;
    }

    public static class TabsAdapter extends FragmentPagerAdapter implements ActionBar.TabListener, ViewPager.OnPageChangeListener
    {
        private final Context mContext;
        private final ActionBar mActionBar;
        private final ViewPager mViewPager;
        private final ArrayList<TabInfo> mTabs = new ArrayList<TabInfo>();

        static final class TabInfo
        {
            private final Class<?> clss;
            private final Bundle args;

            TabInfo(Class<?> _class, Bundle _args)
            {
                clss = _class;
                args = _args;
            }
        }

        public TabsAdapter(SherlockFragmentActivity activity, ViewPager pager)
        {
            super(activity.getSupportFragmentManager());
            mContext = activity;
            mActionBar = activity.getSupportActionBar();
            mViewPager = pager;
            mViewPager.setAdapter(this);
            mViewPager.setOnPageChangeListener(this);
        }

        public void addTab(ActionBar.Tab tab, Class<?> clss, Bundle args)
        {
            TabInfo info = new TabInfo(clss, args);
            tab.setTag(info);
            tab.setTabListener(this);
            mTabs.add(info);
            mActionBar.addTab(tab);
            notifyDataSetChanged();
        }

        public void removeAllTabs()
        {
            mActionBar.removeAllTabs();
            notifyDataSetChanged();
        }

        @Override
        public int getCount()
        {
            return mTabs.size();
        }

        @Override
        public Fragment getItem(int position)
        {
            TabInfo info = mTabs.get(position);
            return Fragment.instantiate(mContext, info.clss.getName(), info.args);
        }

        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels)
        {
        }

        public void onPageSelected(int position)
        {
            mActionBar.setSelectedNavigationItem(position);
        }

        public void onPageScrollStateChanged(int state)
        {
        }

        public void onTabSelected(Tab tab, FragmentTransaction ft)
        {
            Object tag = tab.getTag();
            for (int i = 0; i < mTabs.size(); i++)
            {
                if (mTabs.get(i) == tag)
                {
                    mViewPager.setCurrentItem(i);
                }
            }
        }

        public void onTabUnselected(Tab tab, FragmentTransaction ft)
        {
        }

        public void onTabReselected(Tab tab, FragmentTransaction ft)
        {
        }
    }

}

The Spiele and Tabelle-Class load into the fragments and runs like i want.
If i click of one category (of the left fragment) the right Tabs with Spiele and Tabelle-Calss loads and run.
But if i click a second time of a other category on the left side the tabs in actionbar are removed and new one load. But there is my problem.
Tabelle and Spiele-Tabs doesnt load again! I have always a blank page! because the to classes doesnt load again…

Here is the code which i refresh the right fragment with the tabs:

SpieleUndTabelleFragment fragment = new SpieleUndTabelleFragment();
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.replace(R.id.item_detail_container, fragment);
ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
ft.commit();

Can anybody help me?!
Thank you!

—————- updated: ———————

i use getFragmetManager() because i have a setOnItemListener() with inner-class. If i want to use getSupportFragmentManager() eclipse say it doestnt support it.
here is the code from onCreateView() from the class:

View view = inflater.inflate(R.layout.waehle_mannschaft, container, false);

    ListView myList = (ListView) view.findViewById(R.id.list);

    myList.setDivider(null);

    final String[] listContent = {"News", "Gästebuch", "Herren 1", "Herren 2", "Herren 3", "Damen 1", "Damen 2", "männl. A", "männl. B1", "männl. B2", "männl. C", "männl. D", "E-Jugend"}; 

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(view.getContext(), android.R.layout.simple_list_item_1, listContent);
    myList.setAdapter(adapter);

    final View v2 = view;
    myList.setOnItemClickListener(new AdapterView.OnItemClickListener()
    {
        public void onItemClick(AdapterView av, View v, int position, long id)
        {
            Toast.makeText(v2.getContext(), listContent[position], Toast.LENGTH_LONG).show();

            if(twoPanels)
            {                   
                SpieleUndTabelleFragment fragment = new SpieleUndTabelleFragment();
                FragmentTransaction ft = getFragmentManager().beginTransaction();
                ft.replace(R.id.item_detail_container, fragment);
                ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
                ft.commit();
            }
            else
            {
                Intent myIntent = new Intent(v2.getContext(), SpieleUndTabelleActivity.class);
                startActivity(myIntent);
            }
        }
    });

    return view;

Spiele is blank at this time. Tabelle show a basic tabelle. Like the image:
enter image description here
and i say it again. the first time i choose a item on the left fragment it do what i want. but if click a second time the # Verein + 0 – Punkte goes away and it is a blank page…beacuse tabelle dont load again…

  • 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-16T01:19:19+00:00Added an answer on June 16, 2026 at 1:19 am

    I think the problem is that onCreateView doesnt get called the second time you load it because it is already created.

    Move the code for attaching the fragment

    to onActivityCreated()

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

Sidebar

Related Questions

My app uses HoneyComb fragments where my left side panel has listview and right
My app is using a ListFragment on left side that the user can use
I am making an app which contains fragments within tabs.In this whenever I try
I have an xml layout for a Fragment (android.support.v4.app.Fragment). When this Fragment is added
So im making this app where user could add UP to 3 images to
In my tablet app I use many Fragments (of one class) next to eachother
App has fragment activity with framelayout container matching parent. User interacts with fragments ui
Activites in my app contain fragments, which in turn contain listview/gridviews that're full of
I am trying to convert one of my apps to now use Fragments. This
I have developed an app in Honeycomb and I am using fragments. This is

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.