title: Recycler View not updating messages from Firebase Database: Android Studio
body: <p>When sending messages to firebase recycler view reading them but recycler view not updating instantly....i have tried notifyDataSetChanged() but not working.................................................................................................................................................................
  MessagingActivity.java</p>
  <pre><code>public class MessagingActivity extends AppCompatActivity {
      RecyclerView recyclerView;
      ImageView ivBack, ivSend;
      EditText etTypeMessage;
      TextView tvName;
      String Receiverphone, image, name;
      CircleImageView civProfile;
      DatabaseReference reference;
      MessagingAdapter adapter;
      ArrayList&lt;MessagingBinding&gt; list;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_messaging);
  
      recyclerView = findViewById(R.id.rv_messagingActivity);
      ivBack = findViewById(R.id.ivBack_messagingActivity);
      etTypeMessage = findViewById(R.id.etTypeMessage_activityMessaging);
      tvName = findViewById(R.id.tvName_activityMessaging);
      civProfile = findViewById(R.id.civProfile_messagingActivity);
      ivSend = findViewById(R.id.ivSend_activityMessaging);
  
      getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
  
      image = getIntent().getStringExtra(&quot;image&quot;);
      name = getIntent().getStringExtra(&quot;name&quot;);
      Receiverphone = getIntent().getStringExtra(&quot;phone&quot;);
  
      tvName.setText(name);
      Picasso.get().load(image).into(civProfile);
  
      reference = FirebaseDatabase.getInstance().getReference().child(&quot;Users&quot;);
  
      ivSend.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Messages messages = new Messages(etTypeMessage.getText().toString(), name, image, Singleton.obj.phone, Receiverphone);
              reference.child(&quot;messages&quot;).push().setValue(messages);
              etTypeMessage.setText(&quot;&quot;);
              adapter.notifyDataSetChanged();
  
          }
      });
  
      LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MessagingActivity.this);
      linearLayoutManager.setStackFromEnd(true);
      recyclerView.setHasFixedSize(true);
      recyclerView.setLayoutManager(linearLayoutManager);
  
  
      list = new ArrayList&lt;&gt;();
      
  
      reference.child(&quot;messages&quot;).addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(@NonNull DataSnapshot snapshot) {
  
              for (DataSnapshot dataSnapshot : snapshot.getChildren()) {
                  Messages messages = dataSnapshot.getValue(Messages.class);
                  if (messages.getSenderphone().equals(Singleton.obj.phone) &amp;&amp; messages.getReceiverPhone().equals(Receiverphone)) {
                      list.add(messages);
                  }
  
              }
              adapter = new MessagingAdapter(list);
              recyclerView.setAdapter(adapter);
              adapter.notifyDataSetChanged();
  
          }
  
          @Override
          public void onCancelled(@NonNull DatabaseError error) {
  
          }
  
      });
  
  
      ivBack.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(MessagingActivity.this, MainActivity.class);
              startActivity(intent);
          }
      });
  
  
  }
  </code></pre>
  <p>}</p>
  <p>MessagingAdapter.java<strong>strong text</strong></p>
  <pre><code>public class MessagingAdapter extends RecyclerView.Adapter {
  
  private ArrayList&lt;MessagingBinding&gt; bindingList;
  
  public MessagingAdapter(ArrayList&lt;MessagingBinding&gt; bindingList) {
      this.bindingList = bindingList;
  }
  
  
  @NonNull
  @Override
  public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view;
      switch (viewType) {
          case (MessagingBinding.TYPE_SENDER):
              view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_sendermessaging, parent, false);
              return new SenderViewHolder(view);
          default:
              view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_receivermessaging, parent, false);
              return new ReceiverViewHodler(view);
  
      }
  }
  
  @Override
  public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
      switch (getItemViewType(position)) {
          case (MessagingBinding.TYPE_SENDER):
              ((SenderViewHolder) holder).bindView(position);
  
              break;
          case (MessagingBinding.TYPE_RECEIVER):
              ((ReceiverViewHodler)holder).bindView(position);
              break;
  
      }
  
  }
  
  @Override
  public int getItemCount() {
      if (bindingList == null) {
          return 0;
      } else {
          return bindingList.size();
      }
  }
  
  @Override
  public int getItemViewType(int position) {
      return bindingList.get(position).getType();
  }
  
  class SenderViewHolder extends RecyclerView.ViewHolder {
      TextView tvSender;
      ImageView ivSender;
  
      public SenderViewHolder(@NonNull View itemView) {
          super(itemView);
          tvSender = itemView.findViewById(R.id.tvSender_listItemsMessaging);
          ivSender = itemView.findViewById(R.id.ivSender_listItemMessaging);
      }
  
      void bindView(int position) {
          SenderMessaging sender = (SenderMessaging) bindingList.get(position);
          tvSender.setText(sender.getTvSenderMsg());
          ivSender.setImageResource(sender.getImg());
      }
  }
  
  //-------------------------------ReceiverViewHolder----------------------------------
  class ReceiverViewHodler extends RecyclerView.ViewHolder {
      TextView tvReceiver;
  
      public ReceiverViewHodler(@NonNull View itemView) {
          super(itemView);
          tvReceiver = itemView.findViewById(R.id.tvReceiver_listItemsMessaging);
      }
  
      void bindView(int position) {
          Messages receiver = (Messages) bindingList.get(position);
          tvReceiver.setText(receiver.getMessage());
  
      }
  }
  </code></pre>
  <p>}</p>