Estela Ubeda
Lurker
I get an error in the requests adapter saying list.size = null. When debugging, I noticed the value event listener is not being triggered and it jumps directly to the adapter = new request adapter I have used the same instantiation of the database reference in other parts of the code and it works so I am not sure why this is happening? help please!
public class Requests extends Fragment {
RecyclerView acted, unseen;
RecyclerView.Adapter adapter, adapter2;
ArrayList<Requestitem> requestitems;
public Requests() {
// Required empty public constructor
}
@override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_requests, container, false);
}
@override
public void onViewCreated(View view, @nullable Bundle savedInstanceState)
{
unseen = getView().findViewById(R.id.recunseen);
acted = getView().findViewById(R.id.reqacted);
unseen.setLayoutManager(new LinearLayoutManager(this.getContext()));
acted.setLayoutManager(new LinearLayoutManager(this.getContext()));
DatabaseReference userefdata = FirebaseDatabase.getInstance().getReference().child("Requests");
userefdata.addValueEventListener(new ValueEventListener() {
@override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot snap : snapshot.getChildren()) {
Requestitem evt = new Requestitem(snap.child("name").getValue(String.class),
snap.child("major").getValue(String.class),
snap.child("time").getValue(String.class),
snap.child("riderid").getValue(String.class),
snap.child("driverid").getValue(String.class),
false
);
requestitems.add(evt);
}
adapter.notifyDataSetChanged();
}
@override
public void onCancelled(@NonNull DatabaseError error) {
}
});
adapter2 = new RequestAdapter(requestitems, new RequestAdapter.OnItemClickListener() {
@override
public void OnItemClick(Requestitem ev) {
showselected(new Profile(ev.getRiderid()));
}
});
adapter = new RequestAdapter(requestitems, new RequestAdapter.OnItemClickListener() {
@override
public void OnItemClick(Requestitem ev) {
showselected(new Profile(ev.getRiderid()));
}
});
acted.setAdapter(adapter2);
unseen.setAdapter(adapter);
}
private void showselected(Fragment f){
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.cont, f)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
}
public class Requests extends Fragment {
RecyclerView acted, unseen;
RecyclerView.Adapter adapter, adapter2;
ArrayList<Requestitem> requestitems;
public Requests() {
// Required empty public constructor
}
@override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_requests, container, false);
}
@override
public void onViewCreated(View view, @nullable Bundle savedInstanceState)
{
unseen = getView().findViewById(R.id.recunseen);
acted = getView().findViewById(R.id.reqacted);
unseen.setLayoutManager(new LinearLayoutManager(this.getContext()));
acted.setLayoutManager(new LinearLayoutManager(this.getContext()));
DatabaseReference userefdata = FirebaseDatabase.getInstance().getReference().child("Requests");
userefdata.addValueEventListener(new ValueEventListener() {
@override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot snap : snapshot.getChildren()) {
Requestitem evt = new Requestitem(snap.child("name").getValue(String.class),
snap.child("major").getValue(String.class),
snap.child("time").getValue(String.class),
snap.child("riderid").getValue(String.class),
snap.child("driverid").getValue(String.class),
false
);
requestitems.add(evt);
}
adapter.notifyDataSetChanged();
}
@override
public void onCancelled(@NonNull DatabaseError error) {
}
});
adapter2 = new RequestAdapter(requestitems, new RequestAdapter.OnItemClickListener() {
@override
public void OnItemClick(Requestitem ev) {
showselected(new Profile(ev.getRiderid()));
}
});
adapter = new RequestAdapter(requestitems, new RequestAdapter.OnItemClickListener() {
@override
public void OnItemClick(Requestitem ev) {
showselected(new Profile(ev.getRiderid()));
}
});
acted.setAdapter(adapter2);
unseen.setAdapter(adapter);
}
private void showselected(Fragment f){
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.cont, f)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
}
}