Recyclerview not updating after activity restart - java

So, I'm not sure about the title of this question but here it goes. I have a recyclerview for my chat room. The first time the activity started it has no problem displaying the messages but after pressing the back button back to the main activity showing all chat rooms then click the same chat room again it displays nothing. Then, after sent a message it can display all the messages again. I'm not sure what happened, help, please. Oh, I already tried a few things and browse the internet but because I'm not sure what the keyword is, so I'm quite stuck now
Okay, here is the thing
First main activity, (ignore the other 2 tabs, it's empty)
Main Activity
Then open a chat room
First time open chat room fine
Then press back button, back to MainActivity, then open the same room and no chat displayed
chat room not displaying anything
Then it displays messages again after sending a new messages
new message
I have tried to place notifyDataSetChanged() on various event like onStart, onCreate etc but nothing works;
here is my chat activity
package com.divistant.chat.ui.chat;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import com.divistant.chat.R;
import com.divistant.signup.UserModel;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.gson.Gson;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class ChatActivity extends AppCompatActivity {
LinearLayout layout;
ImageView send;
EditText message;
ScrollView scrollView;
DatabaseReference refrence1;
DatabaseReference refrence2;
RecyclerView rv;
List<ChatModel> chats = new ArrayList<>();
ChatActivityAdapter adapter;
FirebaseUser cUser;
UserModel target;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat);
Log.w("EVENT","ON Create");
Intent intent = getIntent();
target = (new Gson()).fromJson(intent.getStringExtra("target"),UserModel.class);
send = (ImageView)findViewById(R.id.sendButton);
message = (EditText)findViewById(R.id.messageArea);
scrollView = (ScrollView)findViewById(R.id.scrollView);
rv = (RecyclerView) findViewById(R.id.main_chat_rv);
cUser = FirebaseAuth.getInstance().getCurrentUser();
adapter = new ChatActivityAdapter(chats);
final LinearLayoutManager manager = new LinearLayoutManager(ChatActivity.this,
LinearLayoutManager.VERTICAL, false);
rv.setLayoutManager(manager);
refrence1 = FirebaseDatabase.getInstance()
.getReference()
.child("messages")
.child(cUser.getUid() + "_" + target.getUserId());
refrence2 = FirebaseDatabase.getInstance()
.getReference()
.child("messages")
.child(target.getUserId() + "_" + cUser.getUid());
send.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.w("SEND","send message");
if(message.getText().toString().length() > 0){
ChatModel chat = new ChatModel();
chat.setSender(cUser.getEmail());
chat.setMessage(message.getText().toString());
chat.setReceiver(target.getEmailAddress());
chat.setSenderUid(cUser.getUid());
chat.setReceiverUid(target.getUserId());
chat.setTimestamp((new Date()).getTime());
DatabaseReference ref1 = refrence1.push();
ref1.setValue(chat);
DatabaseReference ref2 = refrence2.push();
ref2.setValue(chat);
message.setText("");
}
}
});
refrence1.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
chats.clear();
for(DataSnapshot snapshot :dataSnapshot.getChildren()){
ChatModel chat = new ChatModel();
chat.setSender(snapshot.child("sender").getValue(String.class));
chat.setMessage(snapshot.child("message").getValue(String.class));
chat.setReceiver(snapshot.child("receiver").getValue(String.class));
chat.setSenderUid(snapshot.child("senderUid").getValue(String.class));
chat.setReceiverUid(snapshot.child("receiverUid").getValue(String.class));
chat.setTimestamp(1592455659978L);
chats.add(chat);
}
adapter.setmChats(chats);
adapter.notifyDataSetChanged();
rv.scrollToPosition(adapter.getItemCount()-1);
Log.e("[CH]","DATACHANGE " + chats.size());
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Log.e("[CH]","CANCEL");
}
});
refrence1.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
chats.clear();
adapter.notifyDataSetChanged();
rv.scrollToPosition(adapter.getItemCount()-1);
}
#Override
public void onChildChanged(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
Log.e("[CH]","DB CHANGE");
}
#Override
public void onChildRemoved(#NonNull DataSnapshot dataSnapshot) {
Log.e("[CH]","DB REMOVE");
}
#Override
public void onChildMoved(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
Log.e("[CH]","Child Moved");
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
Log.e("[CH]","DB ERROR");
}
});
rv.setAdapter(adapter);
}
#Override
protected void onStart() {
super.onStart();
Log.e("[CH]","" + adapter.getItemCount());
}
}
Then, here is my ChatActivityAdapter
package com.divistant.chat.ui.chat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.divistant.chat.R;
import com.google.firebase.auth.FirebaseAuth;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class ChatActivityAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
private static final int VIEW_TYPE_ME = 1;
private static final int VIEW_TYPE_OTHER = 2;
List<ChatModel> mChats;
public void setmChats(List<ChatModel> mChats) {
this.mChats = mChats;
}
public ChatActivityAdapter(List<ChatModel> mChats) {
this.mChats = mChats;
Log.e("ADAPTER","CONSTRUCTED " + mChats.size());
}
#NonNull
#Override
public RecyclerView.ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
RecyclerView.ViewHolder viewHolder = null;
switch (viewType) {
case VIEW_TYPE_ME:
View viewChatMine = layoutInflater.inflate(R.layout.chat_item, parent, false);
viewHolder = new MyChatViewHolder(viewChatMine);
break;
case VIEW_TYPE_OTHER:
View viewChatOther = layoutInflater.inflate(R.layout.chat_item_other, parent, false);
viewHolder = new OtherChatViewHolder(viewChatOther);
break;
}
return viewHolder;
}
#Override
public void onBindViewHolder(#NonNull RecyclerView.ViewHolder holder, int position) {
if (TextUtils.equals(mChats.get(position).senderUid,
FirebaseAuth.getInstance().getCurrentUser().getUid())) {
configureMyChatViewHolder((MyChatViewHolder) holder, position);
} else {
configureOtherChatViewHolder((OtherChatViewHolder) holder, position);
}
}
private void configureMyChatViewHolder(final MyChatViewHolder myChatViewHolder, int position) {
ChatModel chat = mChats.get(position);
SimpleDateFormat sfd = new SimpleDateFormat("hh:mm a");
String date=sfd.format(new Date(chat.timestamp).getTime());
myChatViewHolder.senderMsgTime.setText(date);
myChatViewHolder.txtChatMessage.setText(chat.getMessage());
}
private void configureOtherChatViewHolder(final OtherChatViewHolder otherChatViewHolder, int position) {
final ChatModel chat = mChats.get(position);
SimpleDateFormat sfd = new SimpleDateFormat("hh:mm a");
String date=sfd.format(new Date(chat.timestamp).getTime());
otherChatViewHolder.receiverMsgTime.setText(date);
otherChatViewHolder.txtChatMessage.setText(chat.getMessage());
}
#Override
public int getItemCount() {
return mChats.size();
}
#Override
public int getItemViewType(int position) {
if (TextUtils.equals(mChats.get(position).senderUid,
FirebaseAuth.getInstance().getCurrentUser().getUid())) {
return VIEW_TYPE_ME;
} else {
return VIEW_TYPE_OTHER;
}
}
private static class MyChatViewHolder extends RecyclerView.ViewHolder {
private TextView txtChatMessage, txtUserAlphabet;
private TextView senderMsgTime;
public MyChatViewHolder(View itemView) {
super(itemView);
txtChatMessage = (TextView) itemView.findViewById(R.id.text_view_chat_message);
txtUserAlphabet = (TextView) itemView.findViewById(R.id.text_view_user_alphabet);
senderMsgTime=(TextView) itemView.findViewById(R.id.senderMsgTime);
}
}
private static class OtherChatViewHolder extends RecyclerView.ViewHolder {
private TextView txtChatMessage, txtUserAlphabet;
private TextView receiverMsgTime;
public OtherChatViewHolder(View itemView) {
super(itemView);
txtChatMessage = (TextView) itemView.findViewById(R.id.text_view_chat_message_ot);
txtUserAlphabet = (TextView) itemView.findViewById(R.id.text_view_user_alphabet_ot);
receiverMsgTime=(TextView) itemView.findViewById(R.id.receiverMsgTime_ot);
}
}
}
Thanks

Thats because you are clearing the list on childevent listener and not adding the new child in list and not passing the list to the adapter.
#Override
public void onChildAdded(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
chats.clear();
adapter.notifyDataSetChanged();
rv.scrollToPosition(adapter.getItemCount()-1);
}
Now change the code by adding the lines
#Override
public void onChildAdded(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
chats.clear();
for(DataSnapshot snapshot :dataSnapshot.getChildren()){
ChatModel chat = new ChatModel();
chat.setSender(snapshot.child("sender").getValue(String.class));
chat.setMessage(snapshot.child("message").getValue(String.class));
chat.setReceiver(snapshot.child("receiver").getValue(String.class));
chat.setSenderUid(snapshot.child("senderUid").getValue(String.class));
chat.setReceiverUid(snapshot.child("receiverUid").getValue(String.class));
chat.setTimestamp(1592455659978L);
chats.add(chat);
}
adapter.setmChats(chats);
adapter.notifyDataSetChanged();
rv.scrollToPosition(adapter.getItemCount()-1);
}

in my case i used onResume()
#Override
protected void onResume() {
super.onResume();
adapter.notifyDataSetChanged();
}

Can you put rv.setAdapter(adapter) after rv.setLayoutManager(manager);?
And you verify if the method onDataChange(...) its always called??

You can use the following code in the adapter where you want to refresh recyclerview, for example in #Override public void onBackPressed(){} function. If your chats array changed, you should refresh this adapter.
mAdapter = new ChatActivityAdapter(context, chats.get(chats.size() - 1), chats);
recyclerView.setAdapter(mAdapter);

Related

Failed to Sum up the recyclerview items value

I am totally new to Android Studio.
I created recycleview for Budgeting. I created a Budget description and budget value for each item.
I am trying to sum up all the values of the recyclerview. I have tried different methods over the night but failed to do. PLease help!!!
Adapter:
package com.example.personalwallet.Adapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.cardview.widget.CardView;
import androidx.recyclerview.widget.RecyclerView;
import com.example.personalwallet.Model.Budget;
import com.example.personalwallet.R;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import java.util.ArrayList;
public class recyclerAdapter extends RecyclerView.Adapter<recyclerAdapter.MyViewHolder> {
private ArrayList<Budget> userlist;
private DatabaseReference databaseReference;
private String uId;
int sum=0;
public recyclerAdapter(ArrayList<Budget> userlist,String uId){
this.userlist=userlist;
this.uId = uId;
databaseReference = FirebaseDatabase.getInstance().getReference().child("Users").child(uId).child("Budget");
}
public class MyViewHolder extends RecyclerView.ViewHolder{
private TextView nameTxt,amountTXT;
CardView rootCardView;
ImageView deleteSupplierIV;
public MyViewHolder(final View view){
super(view);
nameTxt = view.findViewById(R.id.name);
amountTXT = view.findViewById(R.id.value);
rootCardView = itemView.findViewById(R.id.single_supplier_cardview_id);
deleteSupplierIV = itemView.findViewById(R.id.delete_supplier_IV);
}
}
#NonNull
#Override
public recyclerAdapter.MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View itemview = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_items,parent,false);
return new MyViewHolder(itemview);
}
#Override
public void onBindViewHolder(#NonNull recyclerAdapter.MyViewHolder holder, int position) {
Budget user = userlist.get(position);
String name,amount;
name = user.getBudgetDescription();
amount = user.getAmount();
holder.nameTxt.setText(name);
holder.amountTXT.setText(amount);
if (user.isVisibilityStatus()){
holder.deleteSupplierIV.setVisibility(View.GONE);
}
holder.rootCardView.setOnLongClickListener(new View.OnLongClickListener() {
#Override
public boolean onLongClick(View v) {
holder.deleteSupplierIV.setVisibility(View.VISIBLE);
user.setVisibilityStatus(false);
return true;
}
});
holder.deleteSupplierIV.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
deleteSupplier(user.getBudgetDescription());
}
private void deleteSupplier(String supplierName) {
DatabaseReference productReference = databaseReference.child(supplierName);
productReference.removeValue();
userlist.remove(position);
notifyItemRemoved(position);
notifyDataSetChanged();
}
});
}
#Override
public int getItemCount() {
return userlist.size();
}
}
Activity Code:
package com.example.personalwallet.NavCategories;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.example.personalwallet.Adapter.recyclerAdapter;
import com.example.personalwallet.AddBudgetActivity;
import com.example.personalwallet.Model.Budget;
import com.example.personalwallet.Prevalent.Prevalent;
import com.example.personalwallet.R;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class Budgets extends AppCompatActivity{
private FloatingActionButton addNewBudgetFAB;
private ArrayList<Budget> userlist;
private RecyclerView recyclerView;
private String uId;
DatabaseReference databaseReference;
recyclerAdapter adapter;
TextView TotalBudgetTv;
public int total_budget =0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_budgets);
userlist = new ArrayList<Budget>();
recyclerView = findViewById(R.id.suppliers_recyclerViewID);
TotalBudgetTv = findViewById(R.id.TotalBudgetTv);
uId = Prevalent.currentOnlineUser.getPhone();
adapter = new recyclerAdapter(userlist,uId);
setUserInfo();
setAdapter();
**for (int i=0; i<userlist.size(); i++){
total_budget = total_budget+Integer.parseInt(userlist.get(i).getAmount());
}**
TotalBudgetTv.setText("Total Budget: " + Integer.toString(total_budget));
addNewBudgetFAB = findViewById(R.id.addNewSuppliersFABID);
addNewBudgetFAB.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(Budgets.this, AddBudgetActivity.class);
startActivity(intent);
}
});
}
private void setAdapter() {
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
}
private void setUserInfo() {
databaseReference = FirebaseDatabase.getInstance().getReference().child("Users").child(uId).child("Budget");
databaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
userlist.clear();
if (snapshot.exists()) {
for (DataSnapshot data : snapshot.getChildren()) {
Budget supplier = data.getValue(Budget.class);
userlist.add(supplier);
adapter.notifyDataSetChanged();
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
}
this is my model class:
package com.example.personalwallet.Model;
public class Budget {
private String BudgetDescription;
private String amount;
public boolean isVisibilityStatus() {
return visibilityStatus;
}
public void setVisibilityStatus(boolean visibilityStatus) {
this.visibilityStatus = visibilityStatus;
}
private boolean visibilityStatus = true;
public Budget(){}
public Budget(String budgetDescription, String amount) {
BudgetDescription = budgetDescription;
this.amount = amount;
}
public String getBudgetDescription() {
return BudgetDescription;
}
public void setBudgetDescription(String budgetDescription) {
BudgetDescription = budgetDescription;
}
public String getAmount() {
return amount;
}
public void setAmount(String amount) {
this.amount = amount;
}
}
Try to put your forloop calculation inside onDataChange because in oncreate method your userlist is empty. So when onDataChange called after that new value added to userlist and calculate your total there.
databaseReference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
userlist.clear();
if (snapshot.exists()) {
for (DataSnapshot data : snapshot.getChildren()) {
Budget supplier = data.getValue(Budget.class);
userlist.add(supplier);
adapter.notifyDataSetChanged();
}
for (int i=0; i<userlist.size(); i++)
{
total_budget = total_budget+Integer.parseInt(userlist.get(i).getAmount());
}
TotalBudgetTv.setText("Total Budget: " + Integer.toString(total_budget));
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
In the adapter's constructor you will get the ArrayList which contains all data. Here, you can run a for loop. which will read each object one by one and add in sum.
public recyclerAdapter(ArrayList<Budget> userlist, String uId){
this.userlist=userlist;
this.uId = uId;
databaseReference = FirebaseDatabase.getInstance().getReference().child("Users").child(uId).child("Budget");
for(int i = 0; i<userlist.size(); i++){
Budget user = userlist.get(i);
sum = sum + user.getAmount();
}
}

Firebase chat app not displaying messages like whatsapp does

I am trying to come up with a chat app using Firebase Recycler adapter. The problem is that the sender's and receiver's chats are not displayed as expected. All the chats are displayed on the right. Despite the text being "Morning", the text is displayed as "Hello".
Below is my code
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.firebase.ui.database.SnapshotParser;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import de.hdodenhof.circleimageview.CircleImageView;
import ultramodern.activity.besha.Adapter.MessageAdapter;
import ultramodern.activity.besha.Model.Chat;
import ultramodern.activity.besha.Model.Users;
public class Complete_new_Group extends AppCompatActivity implements View.OnClickListener{
Button fab,paybtn, depobtn, borrowbtn, borrowicon, depoicon, payicon;
CircleImageView sendtextbutton;
EditText text_send;
RecyclerView chatrecyclerView;
MessageAdapter messageAdapter;
public static final int MESSAGE_RIGHT=0;
public static final int MESSAGE_LEFT=1;
//private String user_id;
#Override
protected void onCreate(Bundle savedInstanceState) { ;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_complete_new__group);
Toast.makeText(this, "This area is still under development", Toast.LENGTH_LONG).show();
fab = findViewById(R.id.fab_complete_group);
paybtn = findViewById(R.id.button6);
depobtn = findViewById(R.id.button5);
borrowbtn = findViewById(R.id.button3);
borrowicon = findViewById(R.id.button8);
depoicon = findViewById(R.id.button9);
payicon = findViewById(R.id.button10);
sendtextbutton = findViewById(R.id.sendtextButton);
text_send = findViewById(R.id.text_send);
chatrecyclerView = findViewById(R.id.chatrecycler);
chatrecyclerView.setLayoutManager(new LinearLayoutManager(this));
fab.setOnClickListener(this);
paybtn.setOnClickListener(this);
depobtn.setOnClickListener(this);
borrowbtn.setOnClickListener(this);
borrowicon.setOnClickListener(this);
depoicon.setOnClickListener(this);
payicon.setOnClickListener(this);
sendtextbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String message = text_send.getText().toString();
if (!message.equals("")){
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
String userId = getIntent().getStringExtra("userId");
sendmessage(message,userId,firebaseUser.getUid());
}
else {
Toast.makeText(Complete_new_Group.this, "You can't send an empty message", Toast.LENGTH_SHORT).show();
}
text_send.setText("");
}
});
final FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
final String user_id;
Intent intent = getIntent();
user_id = intent.getStringExtra("userId");
assert user_id != null;
// Log.d("TRACK",user_id);
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users").child(firebaseUser.getUid());
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
Users users = snapshot.getValue(Users.class);
readMessage(firebaseUser.getUid(),user_id,users.getImageURL());
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
#Override
public void onClick(View view) {
if (view==fab){
paybtn.setVisibility(View.VISIBLE);
depobtn.setVisibility(View.VISIBLE);
borrowbtn.setVisibility(View.VISIBLE);
borrowicon.setVisibility(View.VISIBLE);
depoicon.setVisibility(View.VISIBLE);
payicon.setVisibility(View.VISIBLE);
}
if (view==paybtn){
Intent intent = new Intent(getApplicationContext(),Group_pay.class);
startActivity(intent);
}
if (view==payicon){
Intent intent = new Intent(getApplicationContext(),Group_pay_icon_activity.class);
startActivity(intent);
}
if (view==depobtn){
Intent intent = new Intent(getApplicationContext(),Group_deposit_button_activity.class);
startActivity(intent);
}
if (view==depoicon){
Intent intent = new Intent(getApplicationContext(),Group_depo_icon_activity.class);
startActivity(intent);
}
if (view==borrowbtn){
Intent intent = new Intent(getApplicationContext(),Group_deposit_button_activity.class);
startActivity(intent);
}
if (view==borrowicon){
Intent intent = new Intent(getApplicationContext(),Group_borrow_icon_activity.class);
startActivity(intent);
}
if (view==sendtextbutton){
}
}
private void sendmessage(String message,String sender, String reciever){
DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
HashMap<String,Object> hashMap = new HashMap<>();
hashMap.put("sender",sender);
hashMap.put("reciever",reciever);
hashMap.put("message",message);
reference.child("Chats").push().setValue(hashMap);
}
private void readMessage(final String myId, final String userId, String imageURL){
DatabaseReference databaseReference = FirebaseDatabase.getInstance().getReference("Chats");
FirebaseRecyclerOptions<Chat> firebaseRecyclerOptions = new FirebaseRecyclerOptions.Builder<Chat>().setQuery(databaseReference, new SnapshotParser<Chat>() {
#NonNull
#Override
public Chat parseSnapshot(#NonNull DataSnapshot snapshot) {
String message = String.valueOf(snapshot.child("message").getValue());
String sender = String.valueOf(snapshot.child("sender").getValue());
String receiver = String.valueOf(snapshot.child("reciever").getValue());
return new Chat(message,sender,receiver);
}
}).build();
final FirebaseRecyclerAdapter<Chat,ViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Chat,ViewHolder>(firebaseRecyclerOptions) {
#Override
protected void onBindViewHolder(#NonNull final ViewHolder viewHolder, int i, #NonNull Chat chat) {
if (chat.getReceiver().equals(userId) && chat.getSender().equals(myId) || chat.getReceiver()
.equals(myId) && chat.getSender().equals(userId)){
viewHolder.showMessage.setText(chat.getMessage());
}
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
if (viewType == MESSAGE_RIGHT){
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_item_right,parent,false);
return new ViewHolder(view);
}
else {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_item_left,parent,false);
return new ViewHolder(view);
}
}
#Override
public int getItemViewType(int position) {
Chat chat = getItem(position);
FirebaseUser firebaseUser = FirebaseAuth.getInstance().getCurrentUser();
if (chat.getSender().equals(firebaseUser.getUid())){
return MESSAGE_LEFT;
}
else {
return MESSAGE_RIGHT;
}
//return super.getItemViewType(position);
}
};
chatrecyclerView.setAdapter(firebaseRecyclerAdapter);
firebaseRecyclerAdapter.startListening();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView showMessage;
public ImageView profilepic;
public ViewHolder(#NonNull View itemView) {
super(itemView);
showMessage=itemView.findViewById(R.id.showMessage);
profilepic=itemView.findViewById(R.id.profilepic);
}
public void setText(String paramString){
this.showMessage.setText(paramString);
}
}
}
This is the output on both the sender and the receiver
I need some assistance

How to get Int value from an Adapter to Activity in android

I want to get an int value from my adapter class to my activity but I am getting nothing while using this code:
Here is my adapter:
package com.capi.ccecommerceapp.Adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.bumptech.glide.Glide;
import com.capi.ccecommerceapp.Model.Cart;
import com.capi.ccecommerceapp.R;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.List;
public class CartAdapter extends RecyclerView.Adapter<CartAdapter.ViewHolder>
{
private Context context;
private List<Cart> cartList;
private String productImage;
public int overTotalPrice = 0;
public CartAdapter(Context context, List<Cart> cartList ) {
this.context = context;
this.cartList = cartList;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.cart_item, parent, false);
return new ViewHolder(view);
}
#Override
public void onBindViewHolder(#NonNull final ViewHolder holder, final int position) {
holder.cartName.setText(cartList.get(position).getProductName());
holder.cartPrice.setText(cartList.get(position).getProductPrice());
holder.cart_qty.setText(String.valueOf(cartList.get(position).getProductQuantity()));
int oneTypeProductTPrice = ((Integer.parseInt(cartList.get(position).getProductPrice()))) * cartList.get(position).getProductQuantity();
overTotalPrice = overTotalPrice + oneTypeProductTPrice;
/*FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseUser user = auth.getCurrentUser();*/
/* holder.cartPlus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (cartQty<10)
{
cartQty++;
}
}
});
holder.cartMinus.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (cartQty>1)
{
cartQty--;
}
}
});
holder.cart_qty.setText(cartQty);
holder.deleteBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
cartList.remove(cartList.get(position));
}
});*/
/* holder.wishlistBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (holder.wishlistBtn.getTag().equals("add"))
{
holder.wishlistBtn.setImageResource(R.drawable.ic_love_fill);
holder.wishlistBtn.setTag("added");
}
else
{
holder.wishlistBtn.setImageResource(R.drawable.love);
holder.wishlistBtn.setTag("add");
}
}
});*/
DatabaseReference reference = FirebaseDatabase.getInstance().getReference()
.child("Products")
.child(cartList.get(position).getProductId())
.child("productImage");
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot)
{
if (snapshot.exists()) {
productImage = snapshot.getValue(String.class);
Glide.with(context).load(productImage).into(holder.cartImage);
}
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
#Override
public int getItemCount() {
return cartList.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
ImageView cartImage;
TextView cartName;
TextView cartPrice;
ImageView wishlistBtn;
ImageView deleteBtn;
ImageView cartPlus;
ImageView cartMinus;
TextView cart_qty;
public ViewHolder(#NonNull View itemView) {
super(itemView);
cartImage = itemView.findViewById(R.id.cart_image);
cartName = itemView.findViewById(R.id.cart_name);
cartPrice = itemView.findViewById(R.id.cart_price);
wishlistBtn = itemView.findViewById(R.id.add_to_wishlist);
deleteBtn = itemView.findViewById(R.id.delete_cart);
cartPlus = itemView.findViewById(R.id.cart_add);
cartMinus = itemView.findViewById(R.id.cart_minus);
cart_qty = itemView.findViewById(R.id.cart_quantity);
}
}
}
and here is my activity code where I want to set it in textView:
package com.capi.ccecommerceapp.Fragment;
import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import com.capi.ccecommerceapp.Adapter.CartAdapter;
import com.capi.ccecommerceapp.address.ShiptoActivity;
import com.capi.ccecommerceapp.Model.Cart;
import com.capi.ccecommerceapp.R;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
import java.util.List;
public class CartFragment extends Fragment
{
private RecyclerView cartRecyclerView;
private List<Cart> cartList;
private CartAdapter cartAdapter;
private Button next;
private FirebaseAuth auth;
private FirebaseUser user;
private TextView subtotal;
private TextView items;
private TextView shipping;
private TextView totalPrice;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_cart, container, false);
cartRecyclerView = view.findViewById(R.id.cartRecycler);
next = view.findViewById(R.id.checkout_btn);
auth = FirebaseAuth.getInstance();
user = auth.getCurrentUser();
next.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
startActivity(new Intent(getContext(), ShiptoActivity.class));
}
});
subtotal = view.findViewById(R.id.subtotal_price);
items = view.findViewById(R.id.items);
shipping = view.findViewById(R.id.shipping_price);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext());
cartRecyclerView.setLayoutManager(layoutManager);
cartList = new ArrayList<>();
cartAdapter = new CartAdapter(getContext(), cartList);
cartRecyclerView.setAdapter(cartAdapter);
loadCart();
return view;
}
private void loadCart()
{
DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("Cart")
.child(user.getUid());
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
for (DataSnapshot dataSnapshot : snapshot.getChildren())
{
Cart cart = dataSnapshot.getValue(Cart.class);
cartList.add(cart);
}
cartAdapter.notifyDataSetChanged();
subtotal.setText("$" + cartAdapter.overTotalPrice);
items.setText("Items("+cartAdapter.getItemCount()+")");
int shippingPrice = (cartAdapter.overTotalPrice / 20);
shipping.setText("$" + shippingPrice);
/*int totalPriceFinal = shippingPrice + cartAdapter.getOverTotalPrice();
totalPrice.setText("$" + totalPriceFinal);*/
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
}
I want to get this int:public int overTotalPrice = 0;
And I am getting it as:subtotal.setText("$"+cartAdapter.overTotalPrice);
Anyone have a solution?
???????????????????????
????????????????????
??????????????????????

Android Firebase- Not getting all keys as a list, what should I do?

I want to get list of all keys in recyclerview, tried everything but getting nothing, I do not want attributes of keys. Once I get a list of all keys in recyclerview then I will make it clickable and then I want attributes of that key which is clicked please help my this my Final year Project.
I did not use the method setFname of my POJO class because I put my data manually in Firebase.
package com.fyp.phasse_4;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerOptions;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class foodBasketFragment extends Fragment {
private ArrayList<FoodsModel> foodsModels;
private DatabaseReference foodRef;
private FirebaseAuth mAuth;
private String currentUserID;
RecyclerView recyclerView;
String p;
public foodBasketFragment() {
}
#Nullable
#Override
public View onCreateView(#NonNull LayoutInflater inflater, #Nullable final ViewGroup container,
#Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_food_basket, container, false);
foodRef = FirebaseDatabase.getInstance().getReference().child("FoodData");
mAuth = FirebaseAuth.getInstance();
FoodsModel model = new FoodsModel()
recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
currentUserID = mAuth.getCurrentUser().getUid();
foodsModels = new ArrayList<>();
return view;
}
#Override
public void onStart() {
super.onStart();
FirebaseRecyclerOptions options = new FirebaseRecyclerOptions.Builder<FoodsModel>()
.setQuery(foodRef, FoodsModel.class)
.build();
FirebaseRecyclerAdapter<FoodsModel, myViewHolder> adapter = new
FirebaseRecyclerAdapter<FoodsModel, myViewHolder>(options) {
#Override
protected void onBindViewHolder(#NonNull final myViewHolder holder, final int position,
#NonNull final FoodsModel model) {
foodRef.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
}
holder.name.setText();
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
#NonNull
#Override
public myViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.foods_list, parent,
false);
return new myViewHolder(view);
}
};
recyclerView.setAdapter(adapter);
adapter.startListening();
}
public static class myViewHolder extends RecyclerView.ViewHolder
{
TextView name;
public myViewHolder(#NonNull View itemView) {
super(itemView);
name = itemView.findViewById(R.id.txtName);
}
}
}
This is my POJO class,
package com.fyp.phasse_4;
public class FoodsModel {
public String fName;
public FoodsModel() {
}
public FoodsModel(String fName) {
this.fName = fName;
}
public String getfName() {
return fName;
}
public void setfName(String fName) {
this.fName = fName;
}
}
for (DataSnapshot dataSnapshot1 : dataSnapshot.getChildren()) {
String key = dataSnapshot1.getKey();
System.out.println(key);
}

Recyclerview show data again and again when call function multiple times in firebase

Recntly I am working on android project with firebase, I am using recyclerview for showing data. I have added edittext and search button, when we click search button one function call and show its search relevant data. But issue is that when I click the search button it shows the data(suppose only 1 result found) when I click again search button it again append same data, and it shows again and again contineously when I click button.
I am really worried, kindly suggest me whats the issue.
My Adapter code
import android.app.LauncherActivity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
public class Find_donor_Adapter extends RecyclerView.Adapter<Find_donor_Adapter.MyViewHolder> {
Context context;
ArrayList<find_donor_helper> find_donor_helper;
public Find_donor_Adapter(Context context, ArrayList<find_donor_helper> find_donor_helper) {
this.context = context;
this.find_donor_helper = find_donor_helper;
}
#NonNull
#Override
public MyViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
return new MyViewHolder(LayoutInflater.from(context).inflate(R.layout.find_blood_layout,parent,false));
}
#Override
public void onBindViewHolder(#NonNull MyViewHolder holder, int position) {
final find_donor_helper helper = find_donor_helper.get(position);
holder.lname.setText(find_donor_helper.get(position).getFullname());
holder.bldgrp.setText(find_donor_helper.get(position).getBloodgroup());
final String n = helper.getPhonenumber();
holder.lnumber.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
try
{
Intent call = new Intent(Intent.ACTION_CALL);
call.setData(Uri.parse("tel:03465987599"));
call.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(call);
}
catch (Exception e)
{
Toast.makeText(context, ""+e.getMessage(), Toast.LENGTH_LONG).show();
}
}
});
holder.ucall.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent call = new Intent(Intent.ACTION_VIEW);
call.setData(Uri.parse("sms:"+n));
call.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(call);
}
});
Picasso.get().load(helper.getUserimg()).into(holder.uimg);
}
#Override
public int getItemCount() {
return find_donor_helper.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView lname,bldgrp;
Button lnumber,ucall;
ImageView uimg;
public MyViewHolder(#NonNull View itemView) {
super(itemView);
lname = (TextView) itemView.findViewById(R.id.name);
bldgrp = (TextView) itemView.findViewById(R.id.bloodgroup);
lnumber = (Button) itemView.findViewById(R.id.number);
uimg = (ImageView) itemView.findViewById(R.id.userimg);
ucall = (Button) itemView.findViewById(R.id.call);
}
}
}
main code
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;
import com.google.firebase.database.ChildEventListener;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.Query;
import com.google.firebase.database.ValueEventListener;
import java.util.ArrayList;
public class Find_BloodDonator extends AppCompatActivity {
RecyclerView findblood;
ArrayList<find_donor_helper> arrayList;
Find_donor_Adapter adapter;
ProgressDialog pd;
EditText searchtext;
String st;
DatabaseReference reference;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find__blood_donator);
pd = new ProgressDialog(this);
pd.setMessage("Please wait...");
pd.setCanceledOnTouchOutside(false);
pd.setCancelable(false);
findblood = findViewById(R.id.findblood);
findblood.setLayoutManager(new LinearLayoutManager(this));
arrayList = new ArrayList<find_donor_helper>();
//alldata("blooddonor","Yes");
searchtext = findViewById(R.id.searchtext);
st = searchtext.getText().toString();
searchtext.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
alldata("bloodgroup","hello");
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
alldata("bloodgroup","hello");
}
#Override
public void afterTextChanged(Editable s) {
alldata("bloodgroup",s.toString());
}
});
}
private void alldata(String blooddonor,String bloodgroup) {
reference = FirebaseDatabase.getInstance().getReference().child("Users");
Query chk = reference.limitToLast(10).orderByChild(blooddonor).equalTo(bloodgroup);
chk.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
pd.cancel();
try {
for (DataSnapshot dataSnapshot1:dataSnapshot.getChildren())
{
find_donor_helper donor_helper = dataSnapshot1.getValue(find_donor_helper.class);
arrayList.add(donor_helper);
}
adapter = new Find_donor_Adapter(getApplicationContext(),arrayList);
findblood.setAdapter(adapter);
}
catch (Exception e)
{
pd.cancel();
Toast.makeText(Find_BloodDonator.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
pd.cancel();
Toast.makeText(Find_BloodDonator.this, "Server error", Toast.LENGTH_SHORT).show();
}
});
}
}
When you do a new search, your onDataChange gets called with all search results. Then you currently add those search results to arrayList, which means that as you execute additional searches, the list just keeps getting longer.
To only show the results of the latest query, you need to clear arrayList before adding the new search results to it:
Query chk = reference.limitToLast(10).orderByChild(blooddonor).equalTo(bloodgroup);
chk.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
pd.cancel();
arrayList.clear()
try {
for (DataSnapshot dataSnapshot1:dataSnapshot.getChildren()) {
find_donor_helper donor_helper = dataSnapshot1.getValue(find_donor_helper.class);
arrayList.add(donor_helper);
}
adapter = new Find_donor_Adapter(getApplicationContext(),arrayList);
findblood.setAdapter(adapter);
}
catch (Exception e) {
pd.cancel();
Toast.makeText(Find_BloodDonator.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
pd.cancel();
Toast.makeText(Find_BloodDonator.this, "Server error", Toast.LENGTH_SHORT).show();
}
});
Note that you don't need to create a new adapter every time your change arrayList. You can also modify arrayList to contain the up-to-date items (as you already do), and then simply tell the existing adapter to refresh its view(s) with the updated data.
This means you can move the creation of the adapter to your onCreate:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find__blood_donator);
...
arrayList = new ArrayList<find_donor_helper>();
adapter = new Find_donor_Adapter(getApplicationContext(),arrayList);
findblood.setAdapter(adapter);
And then to refresh the data:
Query chk = reference.limitToLast(10).orderByChild(blooddonor).equalTo(bloodgroup);
chk.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
pd.cancel();
arrayList.clear()
try {
for (DataSnapshot dataSnapshot1:dataSnapshot.getChildren()) {
find_donor_helper donor_helper = dataSnapshot1.getValue(find_donor_helper.class);
arrayList.add(donor_helper);
}
adapter.notifyDataSetChanged();
}
catch (Exception e) {
pd.cancel();
Toast.makeText(Find_BloodDonator.this, ""+e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
pd.cancel();
Toast.makeText(Find_BloodDonator.this, "Server error", Toast.LENGTH_SHORT).show();
}
});

Categories