title: the follow button on the itemView is not working properly
body: <p>I use <code>RecyclerView</code> for searching for users.
  the search works fine, but the follow button in the <code>ItemView</code> is not.</p>
  <p>Whenever I press the follow button, the text on the button is supposed to change from &quot;follow&quot; to &quot;following&quot;. and and when I press it again it supposed to change from &quot;following&quot; to &quot;follow&quot;. it was working just fine and suddenly it just stopped working!</p>
  <p>Whenever I press the button it changes from &quot;follow&quot; to &quot;following&quot; for a sec and then it return to &quot;follow&quot;. I couldn't figure out the reason!</p>
  <p>Here is my code.</p>
  <pre><code>public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
  
   final User user = mUsers.get(position);
   isFollowing(user.getId(), holder.btn_follow);
   holder.btn_follow.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  if (holder.btn_follow.getText().toString().equals(&quot;follow&quot;))
                  {
                      FirebaseDatabase.getInstance().getReference().child(&quot;Follow&quot;).child(firebaseUser.getUid())
                              .child(&quot;following&quot;).child(user.getId()).setValue(true);
                      FirebaseDatabase.getInstance().getReference().child(&quot;Follow&quot;).child(user.getId())
                              .child(&quot;followers&quot;).child(firebaseUser.getUid()).setValue(true);
                      addNotifications(user.getId());
                  }
                  else
                  {
                      FirebaseDatabase.getInstance().getReference().child(&quot;Follow&quot;).child(firebaseUser.getUid())
                              .child(&quot;following&quot;).child(user.getId()).removeValue();
                      FirebaseDatabase.getInstance().getReference().child(&quot;Follow&quot;).child(user.getId())
                              .child(&quot;followers&quot;).child(firebaseUser.getUid()).removeValue();
                     // FirebaseDatabase.getInstance().getReference(&quot;Notifications&quot;).child(user.getId()).removeValue();
                  }
              }
          });
      }
  </code></pre>
  <p>Here is the isFollowing function:</p>
  <pre><code>private void isFollowing(final String userid, final Button button) {
          DatabaseReference reference = FirebaseDatabase.getInstance().getReference()
                  .child(&quot;Follow&quot;).child(firebaseUser.getUid()).child(&quot;following&quot;);
          reference.addValueEventListener(new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                  if (dataSnapshot.child(userid).exists()) {
                      button.setText(&quot;following&quot;);
                      button.setBackgroundResource(R.drawable.buttonafter);
                  } else {
                      button.setText(&quot;follow&quot;);
                      button.setBackgroundResource(R.drawable.buttonbefore);
                  }
              }
              @Override
              public void onCancelled(@NonNull DatabaseError databaseError) {
              }
          });
      }
  </code></pre>
  <p><a href="https://i.stack.imgur.com/2lgoy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2lgoy.png" alt="enter image description here" /></a></p>
  <p>It keeps returning to the default &quot;follow&quot; text on the button, so it is not allowing me to follow anyone.</p>
  <p>Please help if you know what's causing this problem.</p>