0
My app was closing at start, I was recommended to pass all code ( creation of the Recycle view ) to the onActivityCreated from Fragment, I did this, the app works, but it should load the recycleview as soon as the app opens, however it does, do this error:
RecyclerView﹕No adapter attached; skipping layout
However when I click on the tab that opens Fragment, after the app is already open, everything works normally. I believe the problem was to have passed pro onActivityCreated, but if you put in Oncreateview, the app doesn’t even open.
Fragment:
package br.com.igoroliv.youtubecanal.fragments;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import br.com.igoroliv.youtubecanal.*;
import br.com.igoroliv.youtubecanal.API.Modelo.PlaylistItem;
import br.com.igoroliv.youtubecanal.Recycle.Adapter;
/**
 * Created by igord on 23/06/2017.
 */
public class fragmentlistavideos extends Fragment {
    private static final String TAG = "Log";
    private TextView txtteste;
    private RecyclerView mRecyclerView;
    private RecyclerView.Adapter mAdapter;
    private List<PlaylistItem> mylistadevideo;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragmentlistavideos, container, false);
        return v;
    }
        @Override
        public void onActivityCreated (@Nullable Bundle savedInstanceState){
            super.onActivityCreated(savedInstanceState);
            try {
                mRecyclerView = (RecyclerView) getActivity().findViewById(R.id.mRecicleview);
                Log.d(TAG, "pegou o recycle do layout");
            } catch (Exception e) {
                Log.d(TAG, "Erro ao pegar o recycle do layout " + e);
            }
            // use this setting to improve performance if you know that changes
            // in content do not change the layout size of the RecyclerView
            mRecyclerView.setHasFixedSize(true);
            Log.d(TAG, "definiu setHasFixedSize como true");
            // defininado o LinearLayoutManager
            LinearLayoutManager llm = new LinearLayoutManager(getActivity());
            llm.setOrientation(LinearLayoutManager.VERTICAL);
            mRecyclerView.setLayoutManager(llm);
            Log.d(TAG, "definiu LinearLayoutManager");
            mylistadevideo = ((MainActivity) getActivity()).getlistavideos();
            Log.d(TAG, "Salvou a lista no mylistadevideo");
            if (mylistadevideo == null) {
                Log.d(TAG, "Lista nula");
            } else {
                mAdapter = new Adapter(mylistadevideo);
                Log.d(TAG, "Definiu o Adapter");
            }
            // specify an adapter (see also next example)
            mRecyclerView.setAdapter(mAdapter);
            Log.d(TAG, "Setou o Adapter");
        }
}
Main Activity with click on tabs:
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        //click nas abas
        BottomBar bottomBar = (BottomBar) findViewById(R.id.bottomBar);
        bottomBar.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelected(@IdRes int tabId) {
                if (tabId == R.id.tab_videos) {
                    //infla o fragment dentro do id ( contentContainer ) do framelayout
                    getSupportFragmentManager().beginTransaction()
                            .add(R.id.contentContainer, new fragmentlistavideos())
                            .replace(R.id.contentContainer,new fragmentlistavideos())
                            .commit();
                }else if (tabId == R.id.tab_chat){
                    //infla o fragment dentro do id ( contentContainer ) do framelayout
                    getSupportFragmentManager().beginTransaction()
                            .add(R.id.contentContainer, new fragmentchat())
                            .replace(R.id.contentContainer,new fragmentchat())
                            .commit();
                }
            }
        });
From what I understand you recommend calling the api and using the list with the result inside the right ? where? can be inside the Onviewcreate?
– Igor Oliveira
I managed, thank you, I passed all the call inside the onviewcreate, and put to set the Adapter inside the retrofit Sponse, everything working :)
– Igor Oliveira
I just couldn’t create an empty list to put in if the list returns null.
– Igor Oliveira
if it returns null, instance it empty (new Arraylist<Playlistitem>())
– Grupo CDS Informática