Reputation: 118
I would like to fetch all other details from a child where i know 1 value of the child
Kindly assist. I would like to get the values of the description and the user. Here is my code;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup
container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab1,container,false);
list = (ListView) view.findViewById(R.id.mylistview);
final DatabaseReference rootRef =
FirebaseDatabase.getInstance().getReference();
final DatabaseReference errandsRef = rootRef.child("Errands");
ValueEventListener eventListener = new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot dataSnapshot) {
for(final DataSnapshot ds : dataSnapshot.getChildren()) {
final String Errand = ds.child("Errand").getValue(String.class);
ll.add(Errand);
ListAdapter adp = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1,ll);
//ll.clear();
list.setAdapter(adp);
list.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String item = (String) list.getItemAtPosition(position);
Kindly assist. Which code should i put inside the onItemClick to fetch the user and the desscription of the item that has been clicked?
Upvotes: 0
Views: 74
Reputation: 712
You can use .orderByChild()
and .equalTo()
. You know the Errand
of clicked item:
String item = (String) list.getItemAtPosition(position);
FirebaseDatabase.getInstance().getReference().child("Errands").orderByChild("Errand").equalTo(item).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
//this dataSnapshot is the your object you want
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
Upvotes: 1