RecyclerView is not priting all the data when the database file works normally

I’m making a simple task manager app for my study but there’s a problem with my recycle view that is not showing all my data. I added 3 different table and it’s only showing the first one on my recyclerview. Was hoping if you guys can help check out what seems to be the problem. I thank you very much for helping

This is my database which works fine
1 Testing 123 Testing to see if work 17/5/2024
2 Testing 456 Testing 2nd time 17/5/2024
3 Tsting again Testing checking the database 31/5/2024

MainActivity.java

package com.example.a41p;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;

import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.widget.Toolbar;


import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

    RecyclerView recyclerView;
    FloatingActionButton add_button;
    MyDatabaseHelper myDB;
    ArrayList<String> task_title, task_description, task_duedate;
    CustomAdapter customAdapter;

    @SuppressLint("CutPasteId")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Initialize views
        recyclerView = findViewById(R.id.recyclerview);
        add_button = findViewById(R.id.floatingActionButton);
        Toolbar toolbar = findViewById(R.id.toolbar);

        toolbar.setNavigationOnClickListener(view -> {
            // Navigate back to MainActivity
            Intent intent = new Intent(MainActivity.this, MainActivity.class);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
            finish(); // Finish current activity
        });

        // Set onClickListener for the FloatingActionButton
        add_button.setOnClickListener(view -> {
            Intent intent = new Intent(MainActivity.this, AddActivity.class);
            addActivityResultLauncher.launch(intent);
        });

        myDB = new MyDatabaseHelper(MainActivity.this);
        task_title = new ArrayList<>();
        task_description = new ArrayList<>();
        task_duedate = new ArrayList<>();

        // Store data from the database into the array
        storeDataInArrays(false);

        // Set up the RecyclerView with the CustomAdapter
        customAdapter = new CustomAdapter(MainActivity.this, this, task_title, task_description, task_duedate);
        recyclerView.setAdapter(customAdapter);
        recyclerView.setLayoutManager(new LinearLayoutManager(MainActivity.this));
    }


    //I think is the problem but seems to look fine
    private final ActivityResultLauncher<Intent> addActivityResultLauncher = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            result -> {
                if (result.getResultCode() == RESULT_OK) {
                    // Append new data to the RecyclerView
                    storeDataInArrays(true);
                    customAdapter.notifyDataSetChanged();
                }
            }
    );

    void storeDataInArrays(boolean append) {
        Cursor cursor = myDB.readAllData();
        if (cursor.getCount() == 0) {
            Toast.makeText(this, "No data.", Toast.LENGTH_SHORT).show();
        } else {
            if (!append) {
                task_title.clear();
                task_description.clear();
                task_duedate.clear();
            }
            while (cursor.moveToNext()) {
                task_title.add(cursor.getString(1));
                task_description.add(cursor.getString(2));
                task_duedate.add(cursor.getString(3));
            }
        }
    }
}

my activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/constraintLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:title="Task List"
            app:titleTextColor="@android:color/white"
            app:layout_scrollFlags="scroll|enterAlways" />

    </com.google.android.material.appbar.AppBarLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerview"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_marginTop="8dp"
        app:layout_constraintTop_toBottomOf="@id/appBarLayout"
        app:layout_constraintBottom_toTopOf="@id/floatingActionButton"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        tools:layout_editor_absoluteY="96dp" />

    <com.google.android.material.floatingactionbutton.FloatingActionButton
        android:id="@+id/floatingActionButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        app:srcCompat="@drawable/ic_add"
        android:layout_gravity="bottom|end"
        android:clickable="true"
        android:focusable="true"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        tools:ignore="ContentDescription,SpeakableTextPresentCheck" />

</androidx.constraintlayout.widget.ConstraintLayout>

This is what it looks like

I think this part is the problem since i did ask chatgpt about it but it said that this looks fine, my goal is just to print out the cardview each time i added a new task.

private final ActivityResultLauncher<Intent> addActivityResultLauncher = registerForActivityResult(
            new ActivityResultContracts.StartActivityForResult(),
            result -> {
                if (result.getResultCode() == RESULT_OK) {
                    // Append new data to the RecyclerView
                    storeDataInArrays(true);
                    customAdapter.notifyDataSetChanged();
                }
            }
    );

This is my CustomApdapter which works with the my_row xml

package com.example.a41p;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.MyViewHolder> {

    private final Context context;
    private final Activity activity;
    private final ArrayList<String> task_title;
    private final ArrayList<String> task_description;
    private final ArrayList<String> task_duedate;

    public CustomAdapter(Activity activity, Context context, ArrayList<String> task_title, ArrayList<String> task_description, ArrayList<String> task_duedate) {
        this.activity = activity;
        this.context = context;
        this.task_title = task_title;
        this.task_description = task_description;
        this.task_duedate = task_duedate;
    }

    @NonNull
    @Override
    public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.my_row, parent, false);
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final MyViewHolder holder, int position) {
        holder.task_title_txt.setText(task_title.get(position));
        holder.task_description_txt.setText(task_description.get(position));
        holder.task_duedate_txt.setText(task_duedate.get(position));

        holder.mainLayout.setOnClickListener(view -> {
            int adapterPosition = holder.getAdapterPosition();
            if (adapterPosition != RecyclerView.NO_POSITION) {
                Intent intent = new Intent(context, UpdateActivity.class);
                intent.putExtra("title", String.valueOf(task_title.get(adapterPosition)));
                intent.putExtra("description", String.valueOf(task_description.get(adapterPosition)));
                intent.putExtra("due date", String.valueOf(task_duedate.get(adapterPosition)));
                context.startActivity(intent);
            }
        });
    }


    @Override
    public int getItemCount() {
        return task_title.size();
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {

        TextView task_title_txt, task_description_txt, task_duedate_txt;
        LinearLayout mainLayout;

        public MyViewHolder(@NonNull View itemView) {
            super(itemView);
            task_title_txt = itemView.findViewById(R.id.task_title_txt);
            task_description_txt = itemView.findViewById(R.id.task_description_txt);
            task_duedate_txt = itemView.findViewById(R.id.task_duedate_txt);
            mainLayout = itemView.findViewById(R.id.mainLayout);
        }
    }

}

my_row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="12dp"
    android:id="@+id/mainLayout">

    <androidx.cardview.widget.CardView
        android:id="@+id/cardView"
        android:layout_width="match_parent"
        android:layout_height="172dp">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:layout_width="match_parent"
            android:layout_height="171dp">

            <TextView
                android:id="@+id/task_title_txt"
                android:layout_width="354dp"
                android:layout_height="38dp"
                android:layout_marginStart="13dp"
                android:layout_marginEnd="12dp"
                android:text="Title"
                android:textColor="@android:color/black"
                android:textSize="30sp"
                android:textStyle="bold"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                tools:ignore="HardcodedText,MissingConstraints"
                tools:layout_editor_absoluteY="7dp" />

            <TextView
                android:id="@+id/task_description_txt"
                android:layout_width="356dp"
                android:layout_height="67dp"
                android:layout_marginStart="13dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="12dp"
                android:text="Description"
                android:textSize="20sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/task_title_txt"
                tools:ignore="HardcodedText,MissingConstraints" />

            <TextView
                android:id="@+id/task_duedate_txt"
                android:layout_width="141dp"
                android:layout_height="29dp"
                android:layout_marginStart="16dp"
                android:layout_marginTop="8dp"
                android:text="Due Date"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/task_description_txt"
                tools:ignore="MissingConstraints" />

        </androidx.constraintlayout.widget.ConstraintLayout>
    </androidx.cardview.widget.CardView>

</LinearLayout>

New contributor

Phúc Đạt Trần is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật