Jump to content
  • Advertisement
Sign in to follow this  

Help with Android dynamic fragments

This topic is 1679 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

edit: i'm editing my post to better explain my problem.


I have an android application using swipe tabs to navigate between fragments. I have 2 fragments defined in xml file and 1 main activity. Whenever I run my application I'm getting the tabs to show up properly with the correct names "Administration", "Scan", "About"... but the page is blank. When I step through my debugger to check the return value of onCreateView (in my FragmentPagerAdapter code below) it appears to be returning correct value... I can't figure out why I keep getting a blank screen.


Here is my activity_main.xml

    <android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"  
    tools:context="com.atd.giftmonster.MainActivity" />  

Here is my MainActivity.java

public class MainActivity extends ActionBarActivity implements ActionBar.TabListener {  
    ViewPager mViewPager;  
    DFragmentManager mFragmentManager;  
    private static EditText textEmail;  
    private static EditText textPw;  
    protected void onCreate(Bundle savedInstanceState) {  
        List<String> titles = new ArrayList<String>();  
        List<Integer> layoutids = new ArrayList<Integer>();  
        // Set up the action bar.  
        final ActionBar actionBar = getSupportActionBar();  
        mFragmentManager = new DFragmentManager(getSupportFragmentManager(), layoutids, titles);  
        // Set up the ViewPager with the sections adapter.  
        mViewPager = (ViewPager) findViewById(R.id.pager);  
        // When swiping between different sections, select the corresponding  
        // tab. We can also use ActionBar.Tab#select() to do this if we have  
        // a reference to the Tab.  
        mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {  
            public void onPageSelected(int position) {  
        // For each of the sections in the app, add a tab to the action bar.  
        for (int i = 0; i < mFragmentManager.getCount(); i++) {  

Here is my FragmentPagerAdapter w/ static fragment class

    public class DFragmentManager extends FragmentPagerAdapter {  
    List<String> mTitle;  
    List<Integer> mLayoutID;  
    List<Fragment> mFragments;  
    FragmentManager mFragmentManager;  
    public DFragmentManager(FragmentManager fm, List<Integer> layoutIDs, List<String> layoutTitles)  
        mFragments = new ArrayList<Fragment>();  
        mLayoutID = layoutIDs;  
        mFragmentManager = fm;  
        mTitle = layoutTitles;  
        int size = mLayoutID.size();  
        for (int i = 0; i < size; i++)  
    public Fragment getItem(int position)  
        return mFragments.get(position);  
    public int getCount()  
        return mFragments.size();  
    public CharSequence getPageTitle(int position) {  
        //return (CharSequence)new String("ss");  
        //return (CharSequence) mFragments.get(position).getTitle();  
        return (CharSequence) mTitle.get(position);  
    public Fragment getFragment(int position)  
        return mFragments.get(position);  
    public static class DFragment extends Fragment  
        private View mView;  
        private static final String ARG_LAYOUT_ID = "layout_id";  
        public static final DFragment newInstance(int layoutID)  
            DFragment fragment = new DFragment();  
            Bundle bundle = new Bundle();  
            bundle.putInt(ARG_LAYOUT_ID, layoutID);  
            return fragment;  
        public View onCreateView(LayoutInflater inflater, ViewGroup group, Bundle bundle)  
            int resourceID = getArguments().getInt(ARG_LAYOUT_ID);  
            mView = inflater.inflate(resourceID, group, false);  
            return mView;  
        public View getView()  
            return mView;  
Edited by sc2bigjoe

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!