so i have a recyclerView which contains within it another recyclerView. for some odd reason the main recyclerView isn't being inflated which means the inner one won't be inflated as well, i tried to find the problem for over 3 days now, but i still can't figure out what's the problem.here is what the end result should look like
here is a copy of my code: the main fragment :
public class MainScreen extends Fragment {
private Dialog dialog;
private SchoolViewModel viewModel;
private PaymentsByDateParentAdapter adapter;
private FloatingActionMenu floatingActionMenu,floatingActionMenuList;
private FloatingActionButton addSubject,addTeacher,addPayment;
private FloatingActionButton subjectList,TeacherList;
private RecyclerView recyclerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_main_screen, container, false);
floatingActionMenu = v.findViewById(R.id.fab_add_menu);
floatingActionMenuList = v.findViewById(R.id.fab_list_menu);
addSubject = v.findViewById(R.id.fab_add_subject);
addTeacher = v.findViewById(R.id.fab_add_teacher);
addPayment = v.findViewById(R.id.fab_add_payment);
subjectList = v.findViewById(R.id.fab_list_subject);
TeacherList = v.findViewById(R.id.fab_list_teacher);
recyclerView = v.findViewById(R.id.rv_main_screen);
viewModel = new ViewModelProvider(this).get(SchoolViewModel.class);
List<PaymentByDate> paymentByDateList = new ArrayList<>();
viewModel.getAllPayments().observe(getViewLifecycleOwner(), new Observer<List<Payment>>() {
@RequiresApi(api = Build.VERSION_CODES.N)
@Override
public void onChanged(List<Payment> payments) {
List<String> datesWithDupes = new ArrayList<>();
for(Payment i : payments){
datesWithDupes.add(new String(i.getPaymentDate()));
}
List<String> datesWithoutDupes = datesWithDupes.stream()
.distinct()
.collect(Collectors.toList());
for (String date : datesWithoutDupes) {
viewModel.getPaymentsByDate(date).observe(getViewLifecycleOwner(), new Observer<List<Payment>>() {
@Override
public void onChanged(List<Payment> payments) {
paymentByDateList.add(new PaymentByDate(date,payments));
}
});
v.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getContext(),paymentByDateList.size()+"",Toast.LENGTH_SHORT).show();
}
});
}
}
});
adapter = new PaymentsByDateParentAdapter(paymentByDateList,getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
addSubject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
openDialog();
floatingActionMenu.close(true);
}
});
addTeacher.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(),R.id.nav_host).navigate(R.id.action_mainScreen_to_addTeacher);
floatingActionMenu.close(true);
}
});
addPayment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(),R.id.nav_host).navigate(R.id.action_mainScreen_to_add_payment_fragment);
floatingActionMenu.close(true);
}
});
subjectList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Navigation.findNavController(getActivity(),R.id.nav_host).navigate(R.id.action_mainScreen_to_subjecstListFragment);
floatingActionMenuList.close(true);
}
});
return v;
}
private void openDialog() {
dialog = new Dialog(getContext());
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_add_subject);
dialog.setCancelable(false);
Button confirmSubject = dialog.findViewById(R.id.btn_confirm_subject);
Button cancelSubject = dialog.findViewById(R.id.btn_cacnel_subject);
EditText etSubject = dialog.findViewById(R.id.et_add_subject);
confirmSubject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String subjectName = etSubject.getText().toString();
if (!subjectName.isEmpty()) {
viewModel.addSubject(new Subject(subjectName));
Toast.makeText(getContext(), "confirm", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
dialog.dismiss();
}
});
cancelSubject.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
dialog.getWindow().setGravity(Gravity.CENTER);
dialog.show();
}
the parent adapter class :
public class PaymentsByDateParentAdapter extends RecyclerView.Adapter<PaymentsByDateParentAdapter.PaymentsByDateParentHolder> {
private List<PaymentByDate> paymentByDateList;
private Context context;
public PaymentsByDateParentAdapter(List<PaymentByDate> paymentByDateList, Context context) {
this.paymentByDateList = paymentByDateList;
this.context = context;
}
@NonNull
@Override
public PaymentsByDateParentHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.date_row,parent,false);
return new PaymentsByDateParentHolder(v);
}
@Override
public void onBindViewHolder(@NonNull PaymentsByDateParentHolder holder, int position) {
holder.dateTV.setText(paymentByDateList.get(position).getDate());
holder.recyclerView.setLayoutManager(new LinearLayoutManager(context));
holder.recyclerView.setAdapter(new PaymentsByDateChildAdapter(paymentByDateList.get(position).getPayments()));
}
@Override
public int getItemCount() {
return paymentByDateList.size();
}
protected class PaymentsByDateParentHolder extends RecyclerView.ViewHolder {
private TextView dateTV;
private RecyclerView recyclerView;
public PaymentsByDateParentHolder(@NonNull View itemView) {
super(itemView);
dateTV = itemView.findViewById(R.id.tv_date);
recyclerView = itemView.findViewById(R.id.rv_payments_by_date);
}
}
}
the child adapter class :
public class PaymentsByDateChildAdapter extends RecyclerView.Adapter<PaymentsByDateChildAdapter.PaymentsByDateChildHolder> {
private List<Payment> payments;
public PaymentsByDateChildAdapter(List<Payment> payments) {
this.payments = payments;
}
@NonNull
@Override
public PaymentsByDateChildHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.payments_row,parent,false);
return new PaymentsByDateChildHolder(v);
}
@Override
public void onBindViewHolder(@NonNull PaymentsByDateChildHolder holder, int position) {
holder.hoursTeached.setText(payments.get(position).getHoursTeached());
holder.total.setText(payments.get(position).getPaymentTotal());
}
@Override
public int getItemCount() {
return payments.size();
}
public class PaymentsByDateChildHolder extends RecyclerView.ViewHolder {
private TextView teacherName,hoursTeached,total;
public PaymentsByDateChildHolder(@NonNull View itemView) {
super(itemView);
teacherName = itemView.findViewById(R.id.tv_teacher_name);
hoursTeached = itemView.findViewById(R.id.tv_hours_teached);
total = itemView.findViewById(R.id.tv_total);
}
}
}
here is the xml file for the mainScreen :
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_main_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/fab_add_menu"
android:layout_width="wrap_content"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:menu_colorNormal="#0029FF"
app:menu_colorPressed="#94A5FF">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_add_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_subject_icon"
app:fab_colorNormal="#0029FF"
app:fab_colorPressed="#94A5FF"
app:fab_label="add a subject"
app:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_add_teacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_teacher_icon"
app:fab_colorNormal="#0029FF"
app:fab_colorPressed="#94A5FF"
app:fab_label="add a teacher"
app:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_add_payment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_add_payment_icon"
app:fab_colorNormal="#0029FF"
app:fab_colorPressed="#94A5FF"
app:fab_label="add a payment"
app:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
<com.github.clans.fab.FloatingActionMenu
android:id="@+id/fab_list_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginStart="10dp"
app:menu_labels_position="right"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu_colorNormal="#05FF00"
app:menu_colorPressed="#58FF55">
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_list_subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_subject_icon"
app:fab_colorNormal="#05FF00"
app:fab_colorPressed="#58FF55"
app:fab_label="add a subject"
app:fab_size="mini" />
<com.github.clans.fab.FloatingActionButton
android:id="@+id/fab_list_teacher"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_teacher_icon"
app:fab_colorNormal="#05FF00"
app:fab_colorPressed="#58FF55"
app:fab_label="add a teacher"
app:fab_size="mini" />
</com.github.clans.fab.FloatingActionMenu>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
and the xml file for the parent adapter :
<TextView
android:id="@+id/tv_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="6 mars 2022"
android:textColor="#000"
android:textSize="24sp"
app:fontFamily="@font/k2d_semibold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_payments_by_date"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_date" />
and here is the xml code for the child adapter :
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
app:cardBackgroundColor="#a0a0a0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_teacher_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:text="Prof Raouf Mesran"
android:textColor="#000"
android:textSize="20sp"
app:fontFamily="@font/k2d_semibold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_hours_teached"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:text="3 Heurs"
android:textColor="#000"
android:textSize="20sp"
app:fontFamily="@font/k2d_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tv_total"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3600 DA"
android:textColor="#000"
android:textSize="24sp"
app:fontFamily="@font/k2d_semibold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv_teacher_name" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
if anyone can figure out why am unable to inflate it please let me know. PS: if any extra code is needed please let me know