'How to take input from user in edittexts and show that input related SQLite data in another fragment with the help of Bundle

My goal is to achieve when user click on particular recyclerview item it send the whole item position with related SQLite data to another fragment like that I want to take user input in 3 edittexts and send that inputs with their corresponding custom object data to another fragment. But I don't know how to do that if I send Astadhyayi object it receives blank data and if I make Astadhyayi a Arraylist than it giving me error.

What Result i want https://i.stack.imgur.com/xm1ZB.jpg

What Result im getting now https://i.stack.imgur.com/dj6oP.jpg

This is sender fragment

public class X_APSFragment extends Fragment {

    private EditText et1,et2,et3;
    private static DictionaryDB db;
    private List<Astadhyayi> wordsList = new ArrayList<>();

    private Button btn;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      
        View view = inflater.inflate(R.layout.a_p_s_dialog, container, false);

        et1 =  view.findViewById(R.id.etP1);
        et2 =  view.findViewById(R.id.etP2);
        et3 =  view.findViewById(R.id.etP3);
        btn =  view.findViewById(R.id.btn1);

        String mSAdhyay = et1.getText().toString();
        String mSPada = et2.getText().toString();
        String mSSutraId = et3.getText().toString();

        db = DictionaryDB.getInstance(this.getActivity());
        wordsList = db.getWordsbyAPS(mSAdhyay,mSPada,mSSutraId);

        btn.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {

                    Astadhyayi word = new Astadhyayi();
                     
                    Bundle b = new Bundle();
                    b.putParcelable("allData", word);
 
                    Fragment dFragment = new X_Experiment2Fragment();
                    dFragment.setArguments(b);

                    FragmentTransaction fragTrans =((AppCompatActivity)getContext()).getSupportFragmentManager().beginTransaction();
                    fragTrans.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_CLOSE);
                    fragTrans.replace(R.id.fragment_container, dFragment);
                    fragTrans.addToBackStack(null);
                    fragTrans.commit(); 

                }
            });
        return view;
    }
   
    }
    

This is receiver fragment


public class X_Experiment2Fragment extends Fragment {

    private TextView sutraTV,vrittiTV,padaTv,adhyayTV,sutraIdTV ;
    private static DictionaryDB db;
    
    private Astadhyayi word;
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
       
        View view = inflater.inflate(R.layout.bbb_details_fragment,container,false);
        
        sutraTV = view.findViewById(R.id.tvSutra);
        adhyayTV = view.findViewById(R.id.tVAdhyay);
        padaTv = view.findViewById(R.id.tVPada);
        sutraIdTV = view.findViewById(R.id.tVSutraId);
        vrittiTV = view.findViewById(R.id.tvVritti);
        
        if (getArguments() != null && getArguments().getParcelable("allData") != null) {
            word = getArguments().getParcelable("allData");
        if (word != null) {
            sutraTV.setText(word.getMSutras());
            adhyayTV.setText(word.getMAdhyay());
            padaTv.setText(word.getMPada());
            sutraIdTV.setText(word.getMSutra_id()); 
            vrittiTV.setText(word.getMVritti()); 
        

            //================ @@@@  Get Database Instance   @@@@ ===============\\
           db = DictionaryDB.getInstance(this.getActivity()); 
 
        }
      }
        return view;
    }

My Custom Object Class

public class Astadhyayi implements Parcelable {

    public int mId;
    public String mAdhyay;
    public String mPada;
    public String mSutra_id;
    public String mSutras;
    public String mVritti;
    public String mTopic;
    public String mStatus;

    //**** CONSTRUCTORS
    public Astadhyayi() { }

    public Astadhyayi(int mId, String mAdhyay, String mPada, String mSutra_id, String mSutras, String mVritti, String mTopic) {
        this.mId = mId;
        this.mAdhyay = mAdhyay;
        this.mPada = mPada;
        this.mSutra_id = mSutra_id;
        this.mSutras = mSutras;
        this.mVritti = mVritti;
        this.mTopic = mTopic;
    }

    public Astadhyayi(int mId, String mAdhyay, String mPada, String mSutra_id, String mSutras, String mVritti, String mTopic, String mStatus) {
        this.mId = mId;
        this.mAdhyay = mAdhyay;
        this.mPada = mPada;
        this.mSutra_id = mSutra_id;
        this.mSutras = mSutras;
        this.mVritti = mVritti;
        this.mTopic = mTopic;
        this.mStatus = mStatus;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel par, int inFlag) {

        par.writeInt(mId);
        par.writeString(mAdhyay);
        par.writeString(mPada);
        par.writeString(mSutra_id);
        par.writeString(mSutras);
        par.writeString(mVritti);
        par.writeString(mStatus);
        par.writeString(mTopic);

    }

    public Astadhyayi(Parcel reads) {

        mId = reads.readInt();
        mAdhyay=reads.readString();
        mPada= reads.readString();
        mSutra_id = reads.readString();
        mSutras = reads.readString();
        mVritti = reads.readString();
        mStatus = reads.readString();
        mTopic = reads.readString();
    }

    public static final Creator<Astadhyayi> CREATOR = new Creator<Astadhyayi>() {

        @Override
        public Astadhyayi createFromParcel(Parcel reads) {
            return new Astadhyayi(reads);
        }

        @Override
        public Astadhyayi[] newArray(int size) {
            return new Astadhyayi[size];
        }

    };

    //*** SETTER GETTERS

    public void setMId(int mId) {
        this.mId = mId;
    }

    public int getMId() {
        return mId;
    }

    public void setMAdhyay(String mAdhyay) {
        this.mAdhyay = mAdhyay;
    }

    public String getMAdhyay() {
        return mAdhyay;
    }

    public void setMPada(String mPada) {
        this.mPada = mPada;
    }

    public String getMPada() {
        return mPada;
    }

    public void setMSutra_id(String mSutra_id) {
        this.mSutra_id = mSutra_id;
    }

    public String getMSutra_id() {
        return mSutra_id;
    }

    public void setMSutras(String mSutras) {
        this.mSutras = mSutras;
    }

    public String getMSutras() {
        return mSutras;
    }

    public void setMVritti(String mVritti) {
        this.mVritti = mVritti;
    }

    public String getMVritti() {
        return mVritti;
    }

    public void setMTopic(String mTopic) {
        this.mTopic = mTopic;
    }

    public String getMTopic() {
        return mTopic;
    }

    public void setMStatus(String mStatus) {
        this.mStatus = mStatus;
    }

    public String getMStatus() {
        return mStatus;
    }   
}

My Db Query which I added in sender fragment


public List<Astadhyayi> getWordsbyAPS(String aAdhyays , String pPadas, String sSutraID) {
        SQLiteDatabase db = getReadableDatabase();

        //*****  String sql = "SELECT * FROM " + TABLE_NAME +  " WHERE " + SUTRAS + " LIKE ? ";

        String sql = " SELECT id, adhyay, pada, sutra_id, sutra, vritti, topic, status FROM Astadhyayi_Table WHERE adhyay LIKE ? AND pada LIKE ? AND sutra_id LIKE ? ";

        String  param1 = aAdhyays + "%";
        String  param2 = pPadas + "%";
        String  param3 = sSutraID + "%";
        Cursor cursor = null;
        try {
            cursor = db.rawQuery(sql, new String[]{param1,param2,param3});

            List<Astadhyayi> wordList = new ArrayList<Astadhyayi>();
            while (cursor.moveToNext()) {
                int id = cursor.getInt(0);
                String adhyay = cursor.getString(1);
                String pada = cursor.getString(2);
                String sutra_id = cursor.getString(3);
                String sutras = cursor.getString(4);
                String vritti = cursor.getString(5);
                String topic = cursor.getString(6);
                String status = cursor.getString(7);
                wordList.add(new Astadhyayi(id, adhyay, pada,sutra_id, sutras, vritti,topic ,status));
            }

            return wordList;
        } catch (SQLiteException exception) {
            exception.printStackTrace();
            return null;
        } finally {

            if (cursor != null)
                cursor.close();

            db.close();
        }
    }


If Anyone could help me to achieve my goal it will be very much beneficial for me. Thank You 🙏



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source