title: Android - Firebase on data change refreshes the page
body: <p>I'm kinda newbie to Android.
  I have a recyclerview that I store in Firebase database.
  My recyclerview are made of cardviews.
  Inside each cardview I have a button that updates the node info in Firebase.
  Each time the above is happening, my page refreshes (I guess to load the new data).</p>
  
  <p>My mainactivity code relevant code(called on onCreate) :</p>
  
  <pre><code>  private void loadRecyclerViewData() {
  
      databaseReference.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              if (posts.size() &gt; 0) {
                  posts.clear();
              }
  
              for (DataSnapshot ds : dataSnapshot.getChildren()) {
                  Post post = ds.getValue(Post.class);
                  //Getting a specific user's information (nickname purposes)
                  if (post.getSubGenreType().equals(SubGenreString)) {
                      posts.add(post);
                      Collections.reverse(posts);
                  }
              }
              adapter = new RecyclerAdapter(posts, getApplicationContext());
              recyclerView.setAdapter(adapter);
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  
  
  }
  </code></pre>
  
  <p>my adapter :</p>
  
  <pre><code>public class RecyclerAdapter extends RecyclerView.Adapter&lt;RecyclerAdapter.ViewHolder&gt; {
  public static Boolean isAyed = false;
  private FirebaseAuth firebaseAuth;
  private List&lt;Post&gt; posts;
  private Context context;
  private String userTryToAyeEmail;
  
  public RecyclerAdapter(List&lt;Post&gt; posts, Context context) {
      this.posts = posts;
      this.context = context;
  }
  
  @Override
  public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
      firebaseAuth = FirebaseAuth.getInstance();
  
      View v = LayoutInflater.from(parent.getContext())
              .inflate(R.layout.recycle_card, parent, false);
      return new ViewHolder(v);
  }
  
  @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
  @Override
  public void onBindViewHolder(final ViewHolder holder, final int position) {
      final Post post = posts.get(position);
      holder.imageButton.setVisibility(View.GONE);
      holder.editText.setVisibility(View.GONE);
  
      String colorString = post.getPostColor();
      int color = Color.parseColor(colorString);
      int newNumOfLikes = post.getPostLikes();
      int currentNumOfLikes = post.getPostLikes();
      // holder.cardView.setCardBackgroundColor(color);
      holder.textViewHead.setText(post.getPostContent());
      holder.textViewNickname.setText(post.getPostNickname());
      holder.textViewTimeStamp.setText(post.getPostTimeStamp());
  
      holder.ayeButton.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Boolean userLiked = false;
              if (firebaseAuth.getCurrentUser() != null) {
                  String currentUserEmail = firebaseAuth.getCurrentUser().getEmail();
                  List&lt;String&gt; currentLikedPost = post.getUserLikedList();
                  for (int i = 0; i &lt; currentLikedPost.size(); i++) {
                      if (currentUserEmail.equals(currentLikedPost.get(i))) {
                          currentLikedPost.remove(i);
                          int newNumOfLikes = post.getPostLikes() - 1;
                          updateLikes(post.getId(), newNumOfLikes, post.getPostNickname(), post.getPostTimeStamp(), post.getPostContent(), post.getPostColor(), post.getSubGenreType(), post.getUserLikedList());
                          userLiked = true;
  
                          break;
                      }
                  }
                  if (!userLiked) {
                      currentLikedPost.add(currentUserEmail);
                      int newNumOfLikes = post.getPostLikes() + 1;
                      updateLikes(post.getId(), newNumOfLikes, post.getPostNickname(), post.getPostTimeStamp(), post.getPostContent(), post.getPostColor(), post.getSubGenreType(), post.getUserLikedList());
                  }
              }
          }
      });
  
      if (firebaseAuth.getCurrentUser() != null) {
          String currentUserEmail = firebaseAuth.getCurrentUser().getEmail();
  
          List&lt;String&gt; usersLikedPost = post.getUserLikedList();
          for (int i = 0; i &lt; usersLikedPost.size(); i++) {
              if (currentUserEmail.equals(usersLikedPost.get(i))) {
                  holder.ayeButton.setTextColor(Color.parseColor("#FF0000"));
                  break;
              }
  
          }
      }
  
      holder.ayeTextView.setText(Integer.toString(newNumOfLikes));
  
      holder.cardView.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Intent myIntent = new Intent(context, SinglePostActivity.class);
              myIntent.putExtra("postID", post.getId());
              myIntent.putExtra("postNickname", post.getPostNickname());
              myIntent.putExtra("postTimeStamp", post.getPostTimeStamp());
              myIntent.putExtra("postContent", post.getPostContent());
              myIntent.putExtra("postColor", post.getPostColor());
              context.startActivity(myIntent);
  
          }
      });
  }
  
  private void updateLikes(String id, int newNumOfLikes, String postNickname, String postTimeStamp, String postContent, String postColor, String SubGenre, List&lt;String&gt; userLikedPostList) {
      DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("posts").child(id);
  
      Post post = new Post(postColor, postContent, postNickname, postTimeStamp, id, newNumOfLikes, SubGenre, userLikedPostList);
      databaseReference.setValue(post);
  
  
  }
  
  @Override
  public int getItemCount() {
      return posts.size();
  }
  
  
  public class ViewHolder extends RecyclerView.ViewHolder {
  
      public TextView textViewHead;
      public TextView textViewNickname;
      public TextView textViewTimeStamp;
      public TextView ayeButton;
      public TextView ayeTextView;
      public CardView cardView;
      public LinearLayout linearLayout;
      public EditText editText;
      public ImageButton imageButton;
  
      public ViewHolder(View itemView) {
          super(itemView);
          textViewHead = (TextView) itemView.findViewById(R.id.textViewHead);
          textViewNickname = (TextView) itemView.findViewById(R.id.textViewNickname);
          textViewTimeStamp = (TextView) itemView.findViewById(R.id.textViewTimeStamp);
          ayeButton = (TextView) itemView.findViewById(R.id.ayeButton);
          ayeTextView = (TextView) itemView.findViewById(R.id.ayeTextView);
          cardView = (CardView) itemView.findViewById(R.id.cardViewID);
          linearLayout = (LinearLayout) itemView.findViewById(R.id.cardLinearLayout);
          editText = (EditText) itemView.findViewById(R.id.addCommentEditText);
          imageButton = (ImageButton) itemView.findViewById(R.id.addCommentImageButton);
  
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I wish the page to stay in place, how can I do that ??
  Thank you all.</p>