如何解决GoogleMaps InfoWindow 延迟加载信息
我使用 Firebase 来存储标记数据并在 GoogleMaps 中显示它们。在我创建 InfoWindowAdapter 以显示标记标题和图像之后。我使用这种方法在 InfoWindow 中显示标题和图像:
public class MapInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {
private final View infoWindow;
private Context mContext;
DatabaseReference databaseReference;
Query query;
public MapInfoWindowAdapter(Context context) {
mContext = context;
infoWindow = LayoutInflater.from(context).inflate(R.layout.map_info_window,null);
}
private void renderViewText(Marker marker,View view) {
String title = marker.getTitle();
TextView tvTitle = (TextView) view.findViewById(R.id.mapName);
ImageView imageView = (ImageView) view.findViewById(R.id.mapImageView);
databaseReference = FirebaseDatabase.getInstance().getReference("location");
query = databaseReference.orderByChild("title").equalTo(title);
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
for (DataSnapshot userSnapshot : snapshot.getChildren()) {
String infoTitle = userSnapshot.child("title").getValue().toString();
String infoImage = userSnapshot.child("image").getValue().toString();
Glide.with(imageView).load(infoImage).into(imageView);
tvTitle.setText(infoTitle);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
@Override
public View getInfoWindow(@NonNull Marker marker) {
renderViewText(marker,infoWindow);
return infoWindow;
}
@Override
public View getInfoContents(@NonNull Marker marker) {
renderViewText(marker,infoWindow);
return infoWindow;
}
}
我的问题是,点击标记后,它会显示默认图像和标题(设置为 TextView 和 ImageView)。只有在第二次按下后才会显示正确的信息。我必须按每个标记两次才能显示正确的信息,第一次按打开 InfoWindow,第二次按同一标记加载正确的数据。第一次按下后如何让它显示正确的数据?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。