Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

Help with Android dynamic fragments

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 sc2bigjoe   Members   


Posted 14 May 2014 - 05:36 PM

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, 15 May 2014 - 04:12 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.