Error while creating android studio Fragment

Asked

Viewed 171 times

1

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

Recyclerview: No Adapter Attached; Skipping layout

my main Activity ta so:

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"/>

Adapter class

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];
}

1 answer

0

In the official documentation is used in a way very similar to 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;
    }

}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.