I am trying to display data from a an array list but after the marker onclick it only displays the last element in the array list in the material dialog box
DriverLocationDataManager gets all the data snapshots of the geopoints of the drivers in the database
after adding in all the driver data, i use the addMarker function which gets the geopoints and set the markers on the map.
//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;
});
}
}
}
};
I invite you to read the official developer guide here . It explains how to properly use Dialogs, how to display a list in it, and even how to implement a custom view if you need one to display your list.
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.