Error creating fragment android studio

1

I'm doing an android course that has navigation in bars and for that is used fragments, I did the way the video however the tabs appear but the content of the fragments does not, in the console I have this error:

RecyclerView: No adapter attached; skipping layout

My main activity looks like this:

viewPager = (ViewPager) findViewById(R.id.vp_pagina);
//configurar adaptador
    TabAdapter tabAdapter = new TabAdapter(getSupportFragmentManager());
    viewPager.setAdapter(tabAdapter);

    slidingTabLayout.setViewPager(viewPager);

//xml 
 <android.support.v4.view.ViewPager android:id="@+id/vp_pagina"
    android:layout_width="match_parent" android:layout_height="0dp"
    android:layout_weight="1"/>

Class adapter

public TabAdapter(FragmentManager fm) {
    super(fm);
}

@Override
public Fragment getItem(int position) {

    Fragment fragment = null;

    switch (position){
        case 0:
            fragment = new ConversasFragment();
            break;
        case 1:
            fragment = new ContatosFragment();
            break;
    }

    return fragment;

}

@Override
public int getCount() {
    return tituloAbas.length;
}

@Override
public CharSequence getPageTitle(int position) {
    return tituloAbas[position];
}
    
asked by anonymous 07.01.2018 / 01:03

1 answer

0

At official documentation is used much like yours, but use this suggestion that can give you a great result.

@Override
public Fragment getItem(int position) {

    switch (position){
        case 0:
            ConversasFragment conversasFragment = new ConversasFragment();
            return conversasFragment;
        case 1:
            ContatosFragment contatosFragment = new ContatosFragment();
            return contatosFragment;
        default:
            return null;
    }

}
    
27.04.2018 / 19:25