title: Recylerview not automatically loading data from firebase Android Studio
body: <p>I have tried everything but my data from firebase is not getting loaded automatically when I open the app and I have to click a edittext to load the data.</p>
  
  <p>I have tried</p>
  
  <pre><code>  adapter.Update(data);
    recycler.invalidate();
    notifyDataSetChanged();
    adapter.notifyDataSetChanged();
  </code></pre>
  
  <p>Please can someone help me out.</p>
  
  <p>EDITED:</p>
  
  <p>I am saving to firebase like this:</p>
  
  <pre><code>    public FirebaseHelper(DatabaseReference db) {
          this.db = db;
      }
      //WRITE IF NOT NULL
      public Boolean save(Spacecraft spacecraft)
      {
          if(spacecraft==null)
          {
              saved=false;
          }else
          {
              try
              {
                  db.child("Spacecraft").push().setValue(spacecraft);
                  saved=true;
              }catch (DatabaseException e)
              {
                  e.printStackTrace();
                  saved=false;
              }
          }
          return saved;
      }
      //IMPLEMENT FETCH DATA AND FILL ARRAYLIST
      private void fetchData(DataSnapshot dataSnapshot)
      {
          spacecrafts.clear();
          for (DataSnapshot ds : dataSnapshot.getChildren())
          {
              Spacecraft spacecraft=ds.getValue(Spacecraft.class);
              spacecrafts.add(spacecraft);
          }
      }
      //READ THEN RETURN ARRAYLIST
      public ArrayList&lt;Spacecraft&gt; retrieve() {
          db.addChildEventListener(new ChildEventListener() {
              @Override
              public void onChildAdded(DataSnapshot dataSnapshot, String s) {
                  fetchData(dataSnapshot);
              }
              @Override
              public void onChildChanged(DataSnapshot dataSnapshot, String s){
  
                  fetchData(dataSnapshot);
              }
          });
          return spacecrafts;
      }
  }
  </code></pre>
  
  <p>My viewholder class</p>
  
  <pre><code>public MyViewHolder(View itemView) {
          super(itemView);
          nameTxt= (TextView) itemView.findViewById(R.id.nameTxt);
          propTxt= (TextView) itemView.findViewById(R.id.propellantTxt);
          descTxt= (TextView) itemView.findViewById(R.id.descTxt);
          itemView.setOnClickListener(this);
      }
      public void setItemClickListener(ItemClickListener itemClickListener)
      {
          this.itemClickListener=itemClickListener;
      }
      @Override
      public void onClick(View view) {
          this.itemClickListener.onItemClick(this.getLayoutPosition());
      }
  </code></pre>
  
  <p>My adapter class</p>
  
  <pre><code>public class MyAdapter extends RecyclerView.Adapter&lt;MyViewHolder&gt; {
      Context c;
      ArrayList&lt;Spacecraft&gt; spacecrafts;
      public MyAdapter(Context c, ArrayList&lt;Spacecraft&gt; spacecrafts) {
          this.c = c;
          this.spacecrafts = spacecrafts;
      }
      @Override
      public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          View v=LayoutInflater.from(c).inflate(R.layout.model,parent,false);
          return new MyViewHolder(v);
      }
      @Override
      public void onBindViewHolder(MyViewHolder holder, int position) {
          final  Spacecraft s=spacecrafts.get(position);
          holder.nameTxt.setText(s.getName());
          holder.propTxt.setText(s.getPropellant());
          holder.descTxt.setText(s.getDescription());
          holder.setItemClickListener(new ItemClickListener() {
              @Override
              public void onItemClick(int pos) {
                  //OPEN DETAI ACTIVITY
                  openDetailActivity(s.getName(),s.getDescription(),s.getPropellant());
              }
          });
      }
      @Override
      public int getItemCount() {
          return spacecrafts.size();
      }
      //OPEN DETAIL ACTIVITY
      private void openDetailActivity(String...details)
      {
          Intent i=new Intent(c,DetailActivity.class);
          i.putExtra("NAME_KEY",details[0]);
          i.putExtra("DESC_KEY",details[1]);
          i.putExtra("PROP_KEY",details[2]);
          c.startActivity(i);
      }
  </code></pre>
  
  <p>in my mainactivity in onCreate I am calling the data like this</p>
  
  <pre><code>recycler = (RecyclerView) rootView.findViewById(R.id.recycler);
  recycler.setLayoutManager(new LinearLayoutManager(getActivity()));
  database = FirebaseDatabase.getInstance().getReference();
  spacecraft = new ArrayList&lt;&gt;();
  firebasehelper = new FirebaseHelper(database);
  adapter = new JAdapter(getActivity(), firebasehelper.retrieve());
  recycler.setAdapter(adapter);
  </code></pre>