我需要帮助。在这里,我已将医院名称从Firebase加载到微调框,如何获取getItemAtposition,因为当我单击医院名称时,它必须被选中并单击我的应用程序中的getDirection按钮,这样它将重新加载到google地图上并在特定的医院上标记选择,所以现在如何在我的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);
}