Setei o adaptar e o layout manager mas o recycler view esta em branco. Não encotro o erro.
- ListaNotasActivity
package shivao.apps.ceep.ui.activity;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import java.util.List;
import shivao.apps.ceep.R;
import shivao.apps.ceep.dao.NotaDAO;
import shivao.apps.ceep.model.Nota;
import shivao.apps.ceep.ui.recycler.adapter.ListaNotasAdapter;
public class ListaNotasActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lista_notas);
RecyclerView listaNotas = findViewById(R.id.lista_notas_recyclerview);
NotaDAO dao = new NotaDAO();
for (int i=0; i <10000; i++){
dao.insere(new Nota("Título " + i,
"Descrição " + i));
}
List<Nota> todasNotas = dao.todos();
listaNotas.setAdapter(new ListaNotasAdapter(this, todasNotas));
listaNotas.setLayoutManager(new LinearLayoutManager(this));
}
}
- ListaNotasAdapter
package shivao.apps.ceep.ui.recycler.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
import shivao.apps.ceep.R;
import shivao.apps.ceep.model.Nota;
public class ListaNotasAdapter extends RecyclerView.Adapter<ListaNotasAdapter.NotaViewHolder> {
private List<Nota> notas;
private Context context;
public ListaNotasAdapter(Context context, List<Nota> notas) {
this.context = context;
this.notas = notas;
}
@NonNull
@Override
public NotaViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View viewCriada = LayoutInflater.from(context).
inflate(R.layout.item_nota, parent, false);
return new NotaViewHolder(viewCriada);
}
@Override
public void onBindViewHolder(@NonNull NotaViewHolder holder, int position) {
Nota nota = notas.get(position);
TextView titulo = holder.itemView.findViewById(R.id.item_nota_titulo);
titulo.setText(nota.getTitulo());
TextView descricao = holder.itemView.findViewById(R.id.item_nota_descricao);
descricao.setText(nota.getDescricao());
}
@Override
public int getItemCount() {
return 0;
}
class NotaViewHolder extends RecyclerView.ViewHolder{
public NotaViewHolder(@NonNull View itemView) {
super(itemView);
}
}
}