How to perfom query SQL IN clause in Firebase Android - java

How do I query SQL IN clause in Firebase Android? I want to use it in a Firebase Recycler adapter to retrieve only some children based on some condition. Something like the following statement:
SQL----> select * from posts where city in(10 cities comes here)
I need a Firebase query to use that in the Firebase Recycler adapter.

The Firebase database does not have the equivalent of SQL's WHERE id IN (1,2,3). In the case of selecting by ID, Firebase's way of retrieving items is equally fast because Firebase pipelines the requests.
Your case is different though, since you're not selecting by ID. Unfortunately there is no way to directly map your query to a equivalent on the Firebase Database.
Instead of trying to make Firebase's NoSQL database do SQL tricks, I highly recommend that you start mapping your data model to something that fits better with a NoSQL database. Some great resources to kick start this process are this article on NoSQL data modeling and our new video series on Firebase for SQL developers.
Also see Firebase complex "contain" queries

I found the solution: we cannot use FirebaseRecyclerAdapter. Instead we have to create custom adapter that extends RecyclerView.ViewHolder.
For passing values to this adapter, first we have to retrieve data using addValueEventListener and then we have to pass values to our adapter.
This is my code...
final ArrayList<Timeline> timelines = new ArrayList<>();
mDatabaseTimeline.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
final Timeline timeline = dataSnapshot.getValue(Timeline.class);
if(timeline != null){
mDatabaseFriends.child(mAuth.getCurrentUser().getUid()).child("active").addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (mAuth.getCurrentUser().getUid().equals(timeline.getUid()) || dataSnapshot.hasChild(timeline.getUid())) {
timelines.add(timeline);
mTimelineRecycler.setAdapter(new RecyclerAdapter(TimelineFragment.this.getContext(), timelines));
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
adapter----->
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
Context context;
ArrayList<Timeline> timeline;
public RecyclerAdapter(Context context, ArrayList<Timeline> timeline) {
this.context = context;
this.timeline = timeline;
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(context);
View row = inflater.inflate(R.layout.timeline_row, parent, false);
TimelineViewHolder holder = new TimelineViewHolder(row);
return holder;
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final String post_key = timeline.get(position).getPostkey();
((TimelineViewHolder) holder).setUsername(timeline.get(position).getUsername());
}
#Override
public int getItemCount() {
return timeline.size();
}
public class TimelineViewHolder extends RecyclerView.ViewHolder {
public TimelineViewHolder(View itemView) {
super(itemView);
view = itemView;
}
public View getView() {
return view;
}
public void setUsername(String username) {
TextView usernameTxtView = (TextView) view.findViewById(R.id.timeline_username);
usernameTxtView.setText(username);
}
}
}

Related

How to connect user to courses and grades realtime database java

In this project I have two types of users (teacher and students). Teacher can add classes and student should be able to choose class and sign in to class, when student is signed in class the teacher should be able to give him a grade. I don't know how to connect user to a class and give him grades.
this is my classesAdapter
public class ClassesAdapter extends FirebaseRecyclerAdapter<Classes, ClassesAdapter.StudentViewHolder> {
/**
* Initialize a {#link RecyclerView.Adapter} that listens to a Firebase query. See
* {#link FirebaseRecyclerOptions} for configuration options.
*
* #param options
*/
public ClassesAdapter(#NonNull FirebaseRecyclerOptions options) {
super(options);
}
protected void onBindViewHolder(#NonNull StudentViewHolder holder, int position, #NonNull Classes model) {
holder.className.setText(model.getCname());
holder.classInfo.setText(model.getDescription());
holder.classUid.setText(model.getUid());
String keyId = this.getRef(position).getKey();
}
#NonNull
#Override
public StudentViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.classes, parent, false);
return new ClassesAdapter.StudentViewHolder(view);
}
public class StudentViewHolder extends RecyclerView.ViewHolder {
TextView className;
TextView classInfo;
TextView classUid;
Button classSignInBtn;
public StudentViewHolder(#NonNull View itemView) {
super(itemView);
className = itemView.findViewById(R.id.classNameTxt);
classInfo = itemView.findViewById(R.id.classInfoTxt);
classUid = itemView.findViewById(R.id.classUidTxt);
classSignInBtn = itemView.findViewById(R.id.classSignInBtn);
int position = getAdapterPosition();
classSignInBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
FirebaseAuth mAuth = FirebaseAuth.getInstance();
String uId = mAuth.getCurrentUser().getUid();
FirebaseDatabase db = FirebaseDatabase.getInstance();
DatabaseReference ref = db.getReference("ednevnik/korisnici/" + uId);
DatabaseReference ref1 = db.getReference("ednevnik/razredi/");
ref.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
String name = snapshot.child("name").getValue().toString();
String email = snapshot.child("email").getValue().toString();
String grade = " ";
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
}
});
}
}
}
Welcome to the StackOverflow. Well, I have a similar issue with the real-time database. The issue with this type of database is that it is foresight for fast and response in real-time, which means that this type of database is for chat applications, and generally for response in real-time. My suggestion is to migrate your data to the Cloud Firestore database which is for this kind of application, I had a similar issue.
Here is the documentation for the Cloud Firestore database for Android:
https://firebase.google.com/docs/firestore
Practically, this function is an issue:
ref.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot snapshot) {
String name = snapshot.child("name").getValue().toString();
String email = snapshot.child("email").getValue().toString();
String grade = " ";
}
#Override
public void onCancelled(#NonNull DatabaseError error) {
}
});
You are retrieving data when data is changing inside the database, and that event is not going to happen. That's why I am suggesting the Cloud Firestore database.
I guess that this helps you.
Best Regards,
Sanady

How to Properly Transfer Data from a Model Class to a RecyclerAdapter Class Using an ArrayList (Data Retrieval from Firebase Realtime Database)

I am attempting to load an undetermined number of viewHolders into a recyclerView with data retrieved from the Firebase Realtime Database. This is for a messaging component of my Android app. I am first iterating through a list of chat keys (see "Chat Keys" node below) stored in the database under the current user's userID. For each key, I access the specific associated chat (see "Chat Basics" node below). For testing purposes, I am only retrieving and setting one value type ("lastMessage"), however I intend to set multiple values per viewHolder after successful testing. I am unsure about how to correctly pass the data stored in my model class for each iteration to my onBindViewHolder in my adapter class for display in individual viewholders.
I have had success in retrieving "lastMessage" for each iteration in my fragment class, then passing a string to my adapter class for each iteration. The viewHolders did display the correct string values. Though I can do this successfully, I need to be able to pass an arrayList of data for each iteration, so that I am not limited to only passing a single value per key. Because the onBindViewHolder in the adapter class is position dependent, it is my understanding that I cannot simply pass an array list with simple strings, but should instead pass an instance (O.O.C -might not be the right word) of the model class in an arrayList to be further accessed in the adapter class.
One way or another, please help me load a set of values into an undetermined number of viewHolders for each Firebase Database chat key iteration based on the code provided below. Cheers.
Model Class:
public class MessagesList {
private String lastMessage;
//Default constructor
public MessagesList() {
}
public MessagesList(String lastMessage) {//String userName,, String profileImage) {
//this.userName = userName;
this.lastMessage = lastMessage;
//this.profileImage = profileImage;
}
public String getLastMessage() {
return lastMessage;
}
public void setLastMessage(String lastMessage) {
this.lastMessage = lastMessage;
}
}
Adapter Class:
public class TestRecyclerViewAdapter extends RecyclerView.Adapter<TestRecyclerViewAdapter.ViewHolder> {
private ItemClickListener mClickListener;
private LayoutInflater mInflater;
private ArrayList<MessagesList> mList;
//Data is passed into the constructor
public TestRecyclerViewAdapter(Context context, ArrayList<MessagesList> messagesList) {
this.mInflater = LayoutInflater.from(context);
this.mList = messagesList;
}
//Inflates the row layout from xml when needed
#Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = mInflater.inflate(R.layout.standard_chat_list_layout, parent, false);
return new ViewHolder(view);
}
//Binds the data to the TextView in each row
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.chatListLastMessage.setText(mList.get(position).getLastMessage());
}
//Total number of rows
#Override
public int getItemCount() {
return 0;
}
// stores and recycles views as they are scrolled off screen
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView chatListLastMessage;
ViewHolder(View itemView) {
super(itemView);
chatListLastMessage = itemView.findViewById(R.id.chatListLastMessage);
}
#Override
public void onClick(View view) {
if (mClickListener != null) mClickListener.onItemClick(view, getAdapterPosition());
}
}
// allows clicks events to be caught
void setClickListener(ItemClickListener itemClickListener) {
this.mClickListener = itemClickListener;
}
// parent activity will implement this method to respond to click events
public interface ItemClickListener {
void onItemClick(View view, int position);
}
}
Relevant Fragment:
public class MessagingFragment1 extends Fragment {
private DatabaseReference databaseReference;//, personalChatReference;
private RecyclerView directMessageRecycler;
private String currentUserID;
private TestRecyclerViewAdapter adapter;
private ArrayList<MessagesList> list_of_groups = new ArrayList<>();
public MessagingFragment1() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
final View rootView = inflater.inflate(R.layout.fragment_messaging1, container, false);
currentUserID = FirebaseAuth.getInstance().getCurrentUser().getUid();
databaseReference = FirebaseDatabase.getInstance().getReference();
directMessageRecycler = rootView.findViewById(R.id.directMessageRecycler);
//directMessageRecycler.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
directMessageRecycler.setLayoutManager(linearLayoutManager);
//get a reference to the join table mentioned above
databaseReference.child("Chat Keys").child(currentUserID).addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
String groupId = (snapshot.getKey());
databaseReference.child("Chat Basics").child(groupId).addListenerForSingleValueEvent(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshotInner) {
MessagesList messagesList = dataSnapshotInner.getValue(MessagesList.class);
list_of_groups.add(messagesList);
adapter = new TestRecyclerViewAdapter(getActivity(), list_of_groups);
directMessageRecycler.setAdapter(adapter);
//adapter.setClickListener();
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
return rootView;
}
Database Structure (x2):
Turns out I just forgot to return the correct item count
//Total number of rows
#Override
public int getItemCount() {
return mList.size();
}
and the result was a blank recyclerView. Despite the stupid reason for having posted this question, I will leave it as an example for others (like me) who've had difficulty finding a concise, full example of how to retrieve data from Firebase Database using simple key identifiers in one node to find the core data in another node.

Download only part of Database reference in Firebase?

I have a chat app as part of my Android app that stores all messages in a chat room under a Firebase database reference that carries the ID number for that room. As it stands, the RecyclerView that holds the messages in the chat Activity downloads all messages in that room whenever the user enters it, consuming a potentially unwieldy amount of data. How should I go about making it only download the X most recent messages and download X more if the user scrolls to top?
Here is my adapter:
public class ChatRecyclerViewAdapter extends RecyclerView.Adapter<ChatRecyclerViewAdapter.ViewHolder> {
private static final String TAG = "ChatRecyclerViewAdapter";
private String mRoomID;
private Context mContext;
private DatabaseReference mDatabaseReference;
private ArrayList<Message> messageList;
private ChildEventListener mListener = new ChildEventListener() {
#Override
public void onChildAdded(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
// Convert data snapshot from Database into a Message Object
Message message = dataSnapshot.getValue(Message.class);
// Add it to an arrayList of Messages
messageList.add(message);
// Notice Changes
notifyItemInserted(messageList.size());
}
#Override
public void onChildChanged(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
}
#Override
public void onChildRemoved(#NonNull DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(#NonNull DataSnapshot dataSnapshot, #Nullable String s) {
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
};
public ChatRecyclerViewAdapter(Context mContext, ArrayList<String> mMessage, ArrayList<String> mAuthor, String mRoomID, DatabaseReference reference) {
this.mContext = mContext;
this.mRoomID = mRoomID;
messageList = new ArrayList<>();
mDatabaseReference = reference.child(mRoomID+"_messages");
mDatabaseReference.addChildEventListener(mListener);
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
//This method loads layout(fields) of ViewHolder
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.chat_msg_row,parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
// This method fills fields with data for each list item
Log.d(TAG,"onBindViewHolder called");
Message message = messageList.get(position);
holder.message.setText(message.getMessage());
holder.author.setText(message.getAuthor()+":");
}
#Override
public int getItemCount() {
return messageList.size();
}
//Viewholder stores the information about the layout and content of each list item, and serves as a template for each item of a RecyclerView
public class ViewHolder extends RecyclerView.ViewHolder {
TextView author;
TextView message;
RelativeLayout singleMessageContainer;
public ViewHolder(View itemView) {
super(itemView);
author = itemView.findViewById(R.id.chatAuthor);
message = itemView.findViewById(R.id.chatMessage);
singleMessageContainer = itemView.findViewById(R.id.singleMessageContainer);
}
}
void cleanup() {
mDatabaseReference.removeEventListener(mListener);
}
}
If the messages are stored chronologically already (e.g. if you use push() to add them), you can order the messages by their key and get the most recent ones with:
mDatabaseReference = reference.child(mRoomID+"_messages");
Query recentMessages = mDatabaseReference.orderByKey().limitToLast(10);
recentMessages.addChildEventListener(mListener);
As Doug commented, please check the Firebase documentation on queries for more options

Unable to filter query with multiple clauses using Firebase Realtime Database

I'm using Firebase Realtime Database with Firebase UI, however i'm not being able to search with multiple clauses.
What i need is to take the Users that do not have an specific id. As i'm already filtering them by City i need to filter these ones with specific id.
I've been trying to solve it in many ways, however none of them has come to success.
This is my Database
I cant take and render the card with the user with that username.
public class SearchFragment extends android.support.v4.app.Fragment {
private EditText mSearchField;
private ImageButton mSearchBtn;
private RecyclerView mResultList;
private DatabaseReference mUserDatabase;
public static SearchFragment newInstance() { return new SearchFragment(); }
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_search, container, false);
mSearchField = view.findViewById(R.id.search_field);
mSearchBtn = view.findViewById(R.id.search_btn);
mResultList = view.findViewById(R.id.result_list);
mResultList.setHasFixedSize(true);
mResultList.setLayoutManager(new LinearLayoutManager(mResultList.getContext()));
mSearchBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String searchText = mSearchField.getText().toString();
firebaseUserSearch(searchText);
mSearchField.setText("");
}
});
mUserDatabase = FirebaseDatabase.getInstance().getReference("usuarios");
return view;
}
public void firebaseUserSearch(String searchText) {
Toast.makeText(getContext(), "Buscando usuários", Toast.LENGTH_LONG).show();
String searchTextLower = searchText.toLowerCase();
final Query firebaseSearchQuery = mUserDatabase.orderByChild("city").startAt(searchTextLower).endAt(searchTextLower + "\uf8ff");
firebaseSearchQuery.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
GenericTypeIndicator<Map<String, String>> genericTypeIndicator = new GenericTypeIndicator<Map<String, String>>() {};
Map<String, String> map = dataSnapshot.getValue(genericTypeIndicator );
String username = map.get("username").toString();
Log.d("oi", username);
Log.d("olar", UserDetails.username);
if(username != UserDetails.username) {
final FirebaseRecyclerOptions<User> options =
new FirebaseRecyclerOptions.Builder<User>()
.setQuery(firebaseSearchQuery, User.class)
.build();
bindAndBuildFirebaseUi(options);
}
}
public void bindAndBuildFirebaseUi(FirebaseRecyclerOptions options) {
final FirebaseRecyclerAdapter<User, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<User, UsersViewHolder>(options) {
#Override
public UsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_layout, parent, false);
return new UsersViewHolder(v);
}
#Override
protected void onBindViewHolder(final UsersViewHolder holder, int position, final User model) {
holder.bind(model);
Log.d("SearchFragment", "Binded the model");
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
UserDetails.chatWithId = model.getUsername();
UserDetails.chatWith = model.getName();
startActivity(new Intent(getContext(), Chat.class));
}
});
}
};
firebaseRecyclerAdapter.startListening();
mResultList.setAdapter(firebaseRecyclerAdapter);
}
}
As you can see i even tried to filter them throught the database again, howeever, Firebase ui is taking the filter from options which is the first query filtering the users by city.
Does anyone have any idea how to take avoid rendering the users with an specific id???
And i also know that Firebase does not allow to use more than one orderBy.
The Firebase RTDB doesn't support multiple where clauses unfortunately. However, if you denormalize your data properly, you can use one query to link to another ref in the database and effectively filter data in that way. Take a look at the docs: https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md#using-firebaseui-with-indexed-data.
As a side note, you really shouldn't be using the RTDB to store actual data as it won't scale. It's designed for low latency real-time updates for multiplayer stuff or a ticketing app etc. Instead, I'd recommend looking into Firestore, especially if this is a new app.
Here's the hack I mentioned in my comment below:
public class MyAdapter extends FirebaseRecyclerAdapter {
private static final int TYPE_NORMAL = 0;
private static final int TYPE_HIDDEN = 1;
private final View mEmpty = new View(getContext());
public MyAdapter(#NonNull FirestoreRecyclerOptions options) {
super(options);
mEmpty.setVisibility(View.GONE);
}
#Override
public int getItemViewType(int position) {
if (getItem(position).username.equals(UserDetails.username)) {
return TYPE_HIDDEN;
} else {
return TYPE_NORMAL;
}
}
#Override
public UsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_HIDDEN) {
return new UsersViewHolder(mEmpty);
}
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_layout, parent, false);
return new UsersViewHolder(v);
}
#Override
protected void onBindViewHolder(final UsersViewHolder holder, int position, final User model) {
if (getItemViewType(position) == TYPE_HIDDEN) return;
holder.bind(model);
Log.d("SearchFragment", "Binded the model");
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
UserDetails.chatWithId = model.getUsername();
UserDetails.chatWith = model.getName();
startActivity(new Intent(getContext(), Chat.class));
}
});
}
}

FirebaseUI does not allow me to search for more than one using Firebase Database

I have an array of username(ids) which i need to search using Firebase Database and rendering using Firebase UI, the way that i am doing it is only showing the last user and not all of the users that have those ids. I need to render the cards or all the users with different ids.
This is my class
public class UserMessageListFragment extends Fragment {
private ProgressDialog progressDialog;
private final String TAG = "UsersMessageList";
private RecyclerView mResultList;
private ArrayList<String> arrayUsers;
public static UserMessageListFragment newInstance() {
return new UserMessageListFragment();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_user_message_list, container, false);
mResultList = view.findViewById(R.id.message_list);
mResultList.setHasFixedSize(true);
mResultList.setLayoutManager(new LinearLayoutManager(mResultList.getContext()));
final DatabaseReference refMessages = FirebaseDatabase.getInstance().getReference();
final DatabaseReference ref= FirebaseDatabase.getInstance().getReference().child("usuarios");
refMessages.addChildEventListener(new ChildEventListener() {
#Override
public void onChildAdded(DataSnapshot dataSnapshot, String s) {
if(dataSnapshot.getKey().contains(UserDetails.username+ "_")) {
String[] userChatWithId = dataSnapshot.getKey().split(UserDetails.username+"_");
final Query firebaseSearchQuery = ref.orderByChild("username").equalTo(userChatWithId[1]);
final FirebaseRecyclerOptions<User> options =
new FirebaseRecyclerOptions.Builder<User>()
.setQuery(firebaseSearchQuery, User.class)
.build();
bindAndBuildFirebaseUi(options);
}
}
#Override
public void onChildChanged(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onChildRemoved(DataSnapshot dataSnapshot) {
}
#Override
public void onChildMoved(DataSnapshot dataSnapshot, String s) {
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
// progressDialog = new ProgressDialog(getContext());
// progressDialog.setMessage("Carregando...");
// progressDialog.show();
return view;
}
public void bindAndBuildFirebaseUi(FirebaseRecyclerOptions options) {
final FirebaseRecyclerAdapter<User, UsersViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<User, UsersViewHolder>(options) {
#Override
public UsersViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.message_list_layout, parent, false);
return new UsersViewHolder(v);
}
#Override
protected void onBindViewHolder(final UsersViewHolder holder, int position, final User model) {
holder.bind(model);
holder.itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
UserDetails.chatWithId = model.getUsername();
UserDetails.chatWith = model.getName();
startActivity(new Intent(getContext(), Chat.class));
}
});
}
};
firebaseRecyclerAdapter.startListening();
mResultList.setAdapter(firebaseRecyclerAdapter);
}
}
at this line
final Query firebaseSearchQuery = ref.orderByChild("username").equalTo(userChatWithId[1]);
there will be different values inside userChatWithid1, however FirebaseUI is rendering only the last one.
I am starting to hate FirebaseUI because i've been having so many issues with it.
Can anybody help me, please???
You're doing some very unconventional stuff... FirebaseUI will handle all the database listeners and queries for you. All you should do is pass in the root node that contains all your users and the rest will be taken care of. (I believe in your case it's usuarios so ref will do the trick.) I'd recommend reading the docs: https://github.com/firebase/FirebaseUI-Android/blob/master/database/README.md

Categories

Resources