I am working with recylerviews and Firebase. I am using FirebaseUI to populate data to my recyclerview. I was wondering if it was possible to use two queries within my fragment. The query that should be executed should be dependent of if a node in the database exists.
Database Structure:
If the address child is present in the users node, my fragment should query the users node. If not it should query the routes node. Is this possible?
Basically here I am making by query which gets me all markers:
Query keyQuery = FirebaseDatabase.getInstance().getReference(sharedPreferences.getString("school", null)).child("markers");
recyclerView = (RecyclerView) rootView.findViewById(R.id.markerRecyclerview);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
FirebaseRecyclerOptions<FirebaseMarker> options = new FirebaseRecyclerOptions.Builder<FirebaseMarker>()
.setQuery(keyQuery, FirebaseMarker.class)
.build();
Inside my onBindViewHolder method I have an onClick on each item in the recyclerview. When the item is clicked, the user goes to a new activity. In this new activity the user can press a button which will add the address node under the users/userId node. What pressing that button means is that the user have chosen that marker. So I only want to show that marker information in the recyclerview and not every marker in the database.
holder.mView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(),MainActivity.class);
intent.putExtra("databaseKey", key);
startActivity(intent);
}
});
I was thinking that: If a address and time node was inserted in the users node, I could just query this, which would make it easier.
