2
Hello folks I am creating a chat with Firebase and listing with Recyclerview, to list the messages but I am with a problem is that when moving or scrolling Recyclerview some messages disappear, please help me to solve this!
Here is my code and the images of the result:
//onCreate
ValueEventListener postListener = new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// Get Post object and use the values to update the UI]
Model.clear();
getAllTask(dataSnapshot);
// ...
}
@Override
public void onCancelled(DatabaseError databaseError) {
// Getting Post failed, log a message
Log.w("TAG", "loadPost:onCancelled", databaseError.toException());
// ...
}
};
mData.child("UTILADMIN").addValueEventListener(postListener);
//end onCreate
private void getAllTask(DataSnapshot dataSnapshot){
for(DataSnapshot singleSnapshot : dataSnapshot.getChildren()){
ModelMessage modelMessage = singleSnapshot.getValue(ModelMessage.class);
Model.add(modelMessage);
Adapters adaptador = new Adapters(this, Model, mImageLoader, mUser.getUid());
adaptador.notifyItemInserted(Model.size() - 1);
recyclerView.setAdapter(adaptador);
linearLayoutManager.scrollToPosition(Model.size() - 1);
}
}
onBindViewHolder Solved:
@Override
public void onBindViewHolder(ViewHolders holder, int position) {
if(Mensagem.get(position).getId().equalsIgnoreCase(this.Id)){
holder.chat1.setVisibility(view.GONE); //RelativeLayout chat1 INVISIVEL
holder.chat2.setVisibility(view.VISIBLE);//RelativeLayout chat2 VISIVEL
holder.Nome2.setText(Mensagem.get(position).getNome());
holder.TextMensagem2.setText(Mensagem.get(position).getMensagem());
}else{
holder.chat1.setVisibility(view.VISIBLE);//RelativeLayout chat2 VISIVEL
holder.chat2.setVisibility(view.GONE);//RelativeLayout chat1 INVISIVEL
holder.Nome1.setText(Mensagem.get(position).getNome());
holder.TextMensagem1.setText(Mensagem.get(position).getMensagem());
}
}
Edit the question and add the Adapter code
– ramaral
ready this my Adapter there if it can say what I’m doing wrong I thank you very much!
– Natanael Nael