Partage
  • Partager sur Facebook
  • Partager sur Twitter

[Android]Update marker view recyclerView

    11 octobre 2019 à 15:16:12

    Bonjour, J’essaye de changé la vue sur des Marker depuis un recyclerView le problème c'est que avec mon code quand je Scroll la vue commence a partir sur un autre marker puis revient sur le premier alors que le recyclerView affiche les info du deuxieme Marker. Si quelqu'un a une solution ça m'aiderait beaucoup :)

    Voila mon code : 

     public void onMapReady(GoogleMap googleMap) {
            mMap = googleMap;
    
            try {
                // Customise the styling of the base map using a JSON object defined
                // in a raw resource file.
                boolean success = googleMap.setMapStyle(
                        MapStyleOptions.loadRawResourceStyle(
                                this, R.raw.style_json));
    
                if (!success) {
                    Log.e("MapsActivity", "Style parsing failed.");
                }
            } catch (Resources.NotFoundException e) {
                Log.e("MapsActivity", "Can't find style. Error: ", e);
            }
            Intent intent = getIntent();
            String type = "";
            type = intent.getStringExtra("location");
    
    
    
            request.checkLocationType(type, new MysqlRequest.LocationCallback() {
    
    
                @Override
                public void onSuccess(final List<Location> list) {
    
                    mrecyclerView = findViewById(R.id.recyclerview);
                    GridLayoutManager gridLayoutManager = new GridLayoutManager(MapsActivity.this, 1, GridLayoutManager.HORIZONTAL, false);
                    mrecyclerView.setLayoutManager(gridLayoutManager);
    
    
                    MyAdapter myAdapter = new MyAdapter(MapsActivity.this,list);
                    mrecyclerView.setAdapter(myAdapter);
    
                    for (int i = 0; i < list.size(); i++) {
                        MarkerOptions markerOptions = new MarkerOptions();
                        markerOptions.position(list.get(i).getLatLng());
    
                        markerOptions.icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_selected));
                        markerList.add(mMap.addMarker(markerOptions));
    
    
                    }
                    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(list.get(0).getLatLng(), 10));
    
                    mrecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
                        @Override
                        public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                            super.onScrollStateChanged(recyclerView, newState);
    
                            mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(list.get(newState).getLatLng(), 10));
    
                        }
                    });
    
                }
    
                @Override
                public void dontExist(String message) {
    
                }
    
                @Override
                public void onError(String message) {
    
                }
            });
    
        }
    • Partager sur Facebook
    • Partager sur Twitter
      11 octobre 2019 à 21:46:37

      le paramètre de la fonction "newState" n'est absolument pas la position de ta recyclerView mais une constante qui permet de définir l'état du scrolling.
      • Partager sur Facebook
      • Partager sur Twitter

      [Android]Update marker view recyclerView

      × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
      × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
      • Editeur
      • Markdown