Click here to Skip to main content
15,843,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am achieving this to Simple Recyclerview but i am issue arising when user add or remove …auto populate not . So FirestoreRecycleAdapter can used? Help me ?

i add all snapshots below

Database structure is

collection>Document> array
pickup= value

What I have tried:

myjouurneyorder Fragment code

public class JourneyOrderFragment extends Fragment {

    // TODO: Rename parameter arguments, choose names that match
    // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;

    FirebaseFirestore db;
    RecyclerView recview2;

    RecycleAdapter adapter;

    FloatingActionButton fab;
     ArrayList<model> datalist;
    public JourneyOrderFragment() {
        // Required empty public constructor

    // TODO: Rename and change types and number of parameters
    public static JourneyOrderFragment newInstance(String param1, String param2) {
        JourneyOrderFragment fragment = new JourneyOrderFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        return fragment;

    public void onCreate(Bundle savedInstanceState) {
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment 
        View view=inflater.inflate(R.layout.fragment_journey_order, container, false);
        recview2 =  view.findViewById(;
        recview2.setLayoutManager(new LinearLayoutManager(getContext()));
        datalist=new ArrayList<model> ();
       adapter=new RecycleAdapter(datalist);
        fab.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(getActivity(),"you clicked me i am plus button",Toast.LENGTH_LONG).show();
                Intent intent=new Intent(getActivity(),AddJourneyOrder.class);

         db = FirebaseFirestore.getInstance();
        db.collection("orders").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
                    public void onComplete(@NonNull Task<QuerySnapshot> task) {
                        if (task.isSuccessful()) {
                            for (QueryDocumentSnapshot document : task.getResult()) {

                                ArrayList<model> journeyorders = document.toObject(modelDocument.class).journeyorders;

                    Log.d(TAG, "the document id is : "+document.getId()+"the document is :"+document.getData());

                        } else {
                            Log.d(TAG, "Error getting documents: ", task.getException());
        return view;


2) model class


import java.util.ArrayList;

public class model {

    String pickup;
    String via;
    String drop;


    public model() {

    public model(String pickup,String via,String drop) {
        this.pickup = pickup;
        this.via = via;
        this.drop = drop;

    public String getPickup() {
        return pickup;

    public void setPickup(String pickup) {
        this.pickup = pickup;

    public String getVia() {
        return via;

    public void setVia(String via) {
        this.via = via;

    public String getDrop() {
        return drop;

    public void setDrop(String drop) {
        this.drop = drop;

3) modelDocument class


import java.util.ArrayList;

public class modelDocument {

    public ArrayList<model> journeyorders;

    public void setJourneyorders(ArrayList<model> journeyorders) {
        this.journeyorders = journeyorders;


    public modelDocument() {


4) RecycleAdapter class


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

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


import java.util.ArrayList;
import java.util.List;

public class RecycleAdapter extends RecyclerView.Adapter<recycleadapter.viewholder>{
    ArrayList<model> datalist;
    public RecycleAdapter(ArrayList<model> datalist) {


    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.single_row_design,
                parent, false);
        return new ViewHolder(view);

    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {



    public int getItemCount() {
        return datalist.size();

    class ViewHolder extends RecyclerView.ViewHolder {
        TextView t1;
        TextView t2;
        TextView t3;

        public ViewHolder(View itemView) {
            t1 = itemView.findViewById(;
            t2 = itemView.findViewById(;
            t3 = itemView.findViewById(;

Updated 25-May-22 7:53am
k5054 25-May-22 9:23am    
You've tagged this as C++, but it's clearly Java. Can you fix the tags? That might help getting help with your issue.
Bhumesh Thakur 25-May-22 12:53pm    
its java....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900