public class ToDoAdapter extends RecyclerView.Adapter<ToDoAdapter.MyViewHolder> {
Context context;
ArrayList<ToDoItems> toDoItems;
public ToDoAdapter(Context c, ArrayList<ToDoItems> p) {
context = c;
toDoItems = p;
}
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.front_page_layout, viewGroup, false));
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder myViewHolder, int i) {
myViewHolder.itemTitle.setText(toDoItems.get(i).getItemTitle());
myViewHolder.itemSubject.setText(toDoItems.get(i).getItemSubject());
myViewHolder.itemDueDate.setText(toDoItems.get(i).getItemDueDate());
}
@Override
public int getItemCount() {
return toDoItems.size();
}
class MyViewHolder extends RecyclerView.ViewHolder {
TextView itemTitle;
TextView itemSubject;
TextView itemDueDate;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
itemTitle = itemView.findViewById(R.id.itemTitle);
itemSubject = itemView.findViewById(R.id.itemSubject);
itemDueDate = itemView.findViewById(R.id.itemDueDate);
}
}
}
My Main.class file
//Working with data
mainPageRecyclerView = findViewById(R.id.mainPageRecyclerView);
mainPageRecyclerView.setLayoutManager(new LinearLayoutManager(this));
list = new ArrayList<ToDoItems>();
addNewTask.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent a = new Intent(MainActivity.this,NewTaskAct.class);
startActivity(a);
}
});
//get data from firebase
dbReference = FirebaseDatabase.getInstance().getReference().child("to-do-list");
dbReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//set code to retrieve data and replace layout
for (DataSnapshot dataSnapshot1: dataSnapshot.getChildren())
{
ToDoItems p = dataSnapshot1.getValue(ToDoItems.class);
list.add(p);
}
toDoAdapter = new ToDoAdapter(MainActivity.this, list);
mainPageRecyclerView.setAdapter(toDoAdapter);
toDoAdapter.notifyDataSetChanged();
}
I can see the data in the firebase database but it will not pull the information back from the database and i just get the following error in android studio RUN --> E/RecyclerView: No adapter attached; skipping layout I am writing a simple to do app as part of my learning and i can write information to firebase but i keep getting the above error when my app changes views and needs to call data from the database
I have youtube'd and looked through other stack overflow questions but I can't understand a solution that will work with my project