我正在尝试显示数组列表中的数据但是在标记点击之后 它只显示材料对话框中数组列表中的最后一个元素 DriverLocationDataManager获取数据库中驱动程序的地理位置的所有数据快照
添加所有驱动程序数据后,我使用addMarker函数获取地理位置并在地图上设置标记。
//Init data manager
drivers = new ArrayList<>(0);
dataManager = new DriverLocationDataManager(this) {
@Override
public void onDataLoaded(List<Driver> data) {
if (data.isEmpty()) {
Snackbar.make(container, "Sorry!. UG Shuttle service is currently unavailable",
Snackbar.LENGTH_INDEFINITE).show();
} else {
drivers.addAll(data);
List<Marker> markers = addMarkers(data);
for (int i = 0; i < markers.size(); i++){
markers.get(i);
Driver driver = drivers.get(i);
map.setOnMarkerClickListener(marker -> {
// Get custom view
View v = getLayoutInflater().inflate(R.layout.driver_popup, null, false);
//Assign props
TextView username = v.findViewById(R.id.driver_username);
CircularImageView profile = v.findViewById(R.id.driver_profile);
ImageView status = v.findViewById(R.id.driver_status);
TextView shuttle = v.findViewById(R.id.driver_bus_number);
ViewGroup viewGroup = v.findViewById(R.id.group);
//Init props
Glide.with(getApplicationContext())
.load(driver.getProfile())
.apply(RequestOptions.circleCropTransform())
.apply(RequestOptions.placeholderOf(R.drawable.avatar_placeholder))
.apply(RequestOptions.errorOf(R.drawable.avatar_placeholder))
.apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.AUTOMATIC))
.transition(withCrossFade())
.into(profile);
username.setText(driver.getDriver()); //Driver's username
shuttle.setText(driver.getCarNumber()); //Driver's car number
//Attach to dialog
Builder materialDialog = new Builder(HomeActivity.this)
.customView(v, true)
.negativeText("Dismiss")
.onPositive((dialog, which) -> {
dialog.dismiss();
enableTracking(marker);
})
.onNegative((dialog, which) -> dialog.dismiss());
if (driver.isStatus()) {
status.setImageResource(android.R.color.holo_green_light); //Online
//Enable tracking when driver is online
materialDialog.positiveText("Track")
.onPositive((dialog, which) -> {
dialog.dismiss();
enableTracking(marker);
});
} else {
//Tracking is disabled
status.setImageResource(android.R.color.holo_red_light); //Offline
}
materialDialog.build().show();
return true;
});
}
}
}
};