I have a arraylist which name is exampleList, ı got the value from my firebase database and add them to exampleList. I have checked that there are some values in the exampleList arraylist but out of scope values are gone away. I couldn't understand the reason. Could you please help me.
Note : If I open the comment between HERE lines in the code below ı can see "QUESTION1", "ANSWER1", "A", "B", "C", "D", "E" values on the screen.
Here is my code below;
dbGetData.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
//soru sayısı kadar döner.
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
//PLEASECHECKME NODE U ALTINDAKİ SORULARI ÇEKMİŞ OLDUK
Question = dataSnapshot1.child("question").getValue().toString();
Answer = dataSnapshot1.child("answer").getValue().toString();
A = dataSnapshot1.child("answerA").getValue().toString();
B = dataSnapshot1.child("answerB").getValue().toString();
C = dataSnapshot1.child("answerC").getValue().toString();
D = dataSnapshot1.child("answerD").getValue().toString();
E = dataSnapshot1.child("answerE").getValue().toString();
exampleList.add(new ExampleItem(Question, Answer, A, B, C, D, E));
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
//**************************************************************************************************
mRecyclerView = findViewById(R.id.recyclerView);
mAdapter = new ExampleAdapter(exampleList);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
*****HERE*****
//exampleList.add(new ExampleItem("QUESTION1", "ANSWER1", "A", "B", "C", "D", "E"));
*****HERE*****
mAdapter.notifyDataSetChanged();