У меня есть long переменные и я хочу заполнять RecyclerView объектами и количество объектов должно равняться значению long для этого я сделал легкий цикл
for (int i = 0; i < petiarochkaAmount100; i++) {
couponss.add(new Coupons(R.drawable.petiarochka));
}
Но объекты не добавляются.
Вот весь код
public class LibraryActivity extends BaseActivity {
private static final String TAG = "LibraryActivity";
List<Coupons> couponss = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_library);
setInitialData();
RecyclerView recyclerView = findViewById(R.id.list);
RecyclerAdapter adapter = new RecyclerAdapter(this,couponss);
recyclerView.setAdapter(adapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
}
public void setInitialData(){
DatabaseReference rootRef = FirebaseDatabase.getInstance().getReference();
DatabaseReference uidRef = rootRef.child("users").child(getUid()).child("coupons");
ValueEventListener valueEventListener = new ValueEventListener() {
@SuppressWarnings("ConstantConditions")
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
long petiarochkaAmount100 = dataSnapshot.child("petiarochka").child("petiarochka100").getValue(Long.class);
long petiarochkaAmount300 = dataSnapshot.child("petiarochka").child("petiarochka300").getValue(Long.class);
long petiarochkaAmount500 = dataSnapshot.child("petiarochka").child("petiarochka500").getValue(Long.class);
long lentaAmount100 = dataSnapshot.child("lenta").child("lenta100").getValue(Long.class);
long lentaAmount300 = dataSnapshot.child("lenta").child("lenta300").getValue(Long.class);
long lentaAmount500 = dataSnapshot.child("lenta").child("lenta500").getValue(Long.class);
Log.v("JAJJAJAJAJA",""+petiarochkaAmount100);
for (int i = 0; i < petiarochkaAmount100; i++) {
couponss.add(new Coupons(R.drawable.petiarochka));
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
Log.d(TAG, databaseError.getMessage()); //Don't ignore errors!
}
};
uidRef.addValueEventListener(valueEventListener);
}`
RecyclerAdapter adapter = new RecyclerAdapter(this,couponss);данные еще не попали в массив couponss, соответственно в списке ничего не отображается, он еще пустой. – pavlofff May 18 '19 at 16:35onDataChange()– pavlofff May 18 '19 at 16:37