简体   繁体   English

对话框仅显示数组列表中的最后一项

[英]dialog box displays only the last item in the array list

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 我正在尝试显示数组列表中的数据,但是标记onclick之后,它仅显示材质对话框中数组列表中的最后一个元素
DriverLocationDataManager gets all the data snapshots of the geopoints of the drivers in the database DriverLocationDataManager获取数据库中驱动程序的地理位置的所有数据快照

after adding in all the driver data, i use the addMarker function which gets the geopoints and set the markers on the map. 在添加所有驱动程序数据之后,我使用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;
                    });



                }
            }
        }
    };

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. 它说明了如何正确使用对话框,如何在其中显示列表,以及如果需要一个自定义视图来显示列表,甚至如何实现自定义视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM