Actually I retrieve data from firebase with marker click listener. Each data has unique id.
So when I click care Medical Center in then it goes to another window and another window is given below:
But when i click sust medical then it goes to same window and same data.
Actually main this is same data. How can i retrieve the different data for another marker.
Here is my code:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_h_info);
hosp_name=(TextView) findViewById(R.id.hosp_name);
hosp_email=(TextView) findViewById(R.id.hosp_email);
hosp_num=(TextView) findViewById(R.id.hosp_number);
FirebaseDatabase firebaseDatabase=FirebaseDatabase.getInstance();
DatabaseReference databaseReference1=firebaseDatabase.getReference("H_Information");
databaseReference1.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot dataSnapshot1:dataSnapshot.getChildren())
{
hosp_name.setText(dataSnapshot1.child("hname").getValue().toString());
hosp_email.setText(dataSnapshot1.child("hemail").getValue().toString());
hosp_num.setText(dataSnapshot1.child("hmobile").getValue().toString());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
You need to add a query to retrieve the correct data, for example you can use the equalTo()
:
databaseReference1.orderByChild("hname").equalTo("sust medical").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for(DataSnapshot dataSnapshot1:dataSnapshot.getChildren())
{
hosp_name.setText(dataSnapshot1.child("hname").getValue().toString());
hosp_email.setText(dataSnapshot1.child("hemail").getValue().toString());
hosp_num.setText(dataSnapshot1.child("hmobile").getValue().toString());
}
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
When you click on sust medical, then take the name and pass it to as an argument in equalTo()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.