我需要帮助。在这里,我已将医院名称从 firebase 加载到 spinner 我想如何获取项目Atposition,因为当我单击医院名称时,它必须在我的应用程序中选择并单击 getDirection 按钮,因此它将重新加载到谷歌地图并标记特定的医院选择所以现在如何在我的java代码中做,但我知道缺少一些东西但找不到我请帮助我提前谢谢
Java code
//init Db
hospitalRef = FirebaseDatabase.getInstance().getReference("hospital");
//init interface
iFirebaseLoaddone = this;
hospitalRef.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
List<Hospital> hospital = new ArrayList<>();
for (DataSnapshot hospitalsnapshot : dataSnapshot.getChildren()) {
hospital.add(hospitalsnapshot.getValue(Hospital.class));
}
iFirebaseLoaddone.onFirebaseLoadSuccess(hospital);
}
@Override
public void onCancelled(DatabaseError databaseError) {
iFirebaseLoaddone.onFirebaseLoadFailed(databaseError.getMessage());
}
});
searchableSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String seleceted =parent.getItemAtPosition(position).toString();
Log.e("clicked",""+ seleceted);
hospitalRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
setMarker(dataSnapshot);
// Comment comment = dataSnapshot.getValue(Comment.class);
}
@Override
public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
setMarker(dataSnapshot);
}
@Override
public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
@Override
public void onFirebaseLoadSuccess(List<Hospital> hospitalList) {
hospitals = hospitalList;
//get all data
List<String> id = new ArrayList<>();
List<String> name_list = new ArrayList<>();
List<Double> latitude = new ArrayList<>();
List<Double> longitude = new ArrayList<>();
for (Hospital hospital : hospitalList)
// id.add(hospital.getId());
name_list.add(hospital.getName());
ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, name_list);
searchableSpinner.setAdapter(adapter);
}