Error RecyclerView: No layout manager attached

3

I could not find the error.

My activity:

private AdapterPacientes adapterPacientes;
private static MVP.Presenter presenter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_lista_pacientes);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    if (presenter == null)
        presenter = new Presenter();
    presenter.setActivity(this);
    presenter.retrivePacientes( savedInstanceState );
}

@Override
protected void onStart() {
    super.onStart();

    RecyclerView lista = (RecyclerView) findViewById(R.id.list);
    lista.setHasFixedSize(true);

    adapterPacientes = new AdapterPacientes(presenter.getPacientes());
    lista.setAdapter(adapterPacientes);
}

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putParcelableArrayList(KEY_PACIENTE, presenter.getPacientes());
    super.onSaveInstanceState(outState);
}

@Override
public void refreshAdapter() {
    adapterPacientes.notifyDataSetChanged();
}

// ...

error that appears in the log

I've been searching for more than two hours but I do not think ... The code structure is in the MVP pattern.

Data is being brought in and arraylist is being populated correctly.

Thank you very much.

    
asked by anonymous 09.02.2017 / 05:00

1 answer

5

The error is enlightening: No associated LayoutManager.

One of the differences between RecyclerView and ListView is that RecyclerView is agnostic about how items are visually arranged. This responsibility is performed by the LayoutManager associated with it.

So what's missing is associating one with the RecyclerView. The Android API provides several LayoutManager and you can create your own .

@Override
protected void onStart() {
    super.onStart();

    RecyclerView lista = (RecyclerView) findViewById(R.id.list);
    lista.setHasFixedSize(true);

    //Atribuir LayoutManager
    lista.setLayoutManager(new LinearLayoutManager(this));

    adapterPacientes = new AdapterPacientes(presenter.getPacientes());
    lista.setAdapter(adapterPacientes);
}
    
09.02.2017 / 10:34