OnInfoWindowClickListener не запускается на настраиваемом маркере - PullRequest
0 голосов
/ 06 мая 2020

Я хочу, чтобы, когда пользователь нажимал на информационное окно маркера на карте Google, всплывал AlertDialog.

Я реализую интерфейс GoogleMap.OnInfoWindowClickListener и переопределяю onInfoWindowClick (). Я также установил слушателя внутри onMapReady ().

Как я писал ранее, onInfoWindowClickListener не запускается, НО onInfoWindowLongListener работает правильно.

Есть идеи, почему это происходит?

Ниже приведен код. Я не включил всю часть, только те части, которые имеют отношение к слушателям. Остальная часть кода посвящена совершенно другим функциям

    class UserListFragment : Fragment(),
       OnMapReadyCallback,
       View.OnClickListener,
       GoogleMap.OnInfoWindowClickListener,
       GoogleMap.OnInfoWindowLongClickListener {



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        db = FirebaseFirestore.getInstance()

        if (arguments != null) {
            userList = arguments!!.getParcelableArrayList(getString(R.string.intent_user_list))!!

            userLocations =
                arguments!!.getParcelableArrayList(getString(R.string.intent_user_locations))!!
        }
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {

        val view: View = inflater.inflate(R.layout.fragment_user_list, container, false)!!

        userListRecyclerView = view.findViewById(R.id.user_list_recycler_view)
        mapView = view.findViewById(R.id.user_list_map)
        mapContainer = view.findViewById(R.id.map_container)
        fullScreenBtn = view.findViewById(R.id.btn_full_screen_map)
        fullScreenBtn.setOnClickListener(this)

        initUserListRecyclerView()

        initGoogleMap(savedInstanceState)

        setUserPosition()
        return view
    }

    override fun onMapReady(map: GoogleMap) {

        googleMap = map
        googleMap.setOnInfoWindowClickListener(this)
        googleMap.setOnInfoWindowLongClickListener(this)

        setCameraView()
        addMapMarkers()


    }



    private fun initGoogleMap(savedInstanceState: Bundle?) {

        var mapViewBundle: Bundle? = null

        if (savedInstanceState != null) {
            mapViewBundle = savedInstanceState.getBundle(MAPVIEW_BUNDLE_KEY) as Bundle
        }

        mapView.onCreate(mapViewBundle)
        mapView.getMapAsync(this)
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)

        var mapViewBundle = outState.getBundle(MAPVIEW_BUNDLE_KEY)

        if (mapViewBundle == null) {
            mapViewBundle = Bundle()
            outState.putBundle(MAPVIEW_BUNDLE_KEY, mapViewBundle)
        }
        mapView.onSaveInstanceState(mapViewBundle)
    }

    // This is working properly
    override fun onInfoWindowLongClick(marker: Marker?) {

        if (marker?.snippet == getString(R.string.this_is_you)) {
            marker.hideInfoWindow()
        } else {
            val builder: AlertDialog.Builder = AlertDialog.Builder(activity)
            builder.setMessage(marker?.snippet)
                .setCancelable(true)
                .setPositiveButton(android.R.string.yes, object : DialogInterface.OnClickListener {
                    override fun onClick(dialog: DialogInterface, which: Int) {
                        dialog.dismiss()
                    }
                })
                .setNegativeButton(android.R.string.no, object : DialogInterface.OnClickListener {
                    override fun onClick(dialog: DialogInterface, which: Int) {
                        dialog.cancel()
                    }
                })

            val alertDialog: AlertDialog = builder.create()
            alertDialog.show()

            Log.d(TAG, "onInfoWindowClick: called")

        }
    }

   // This is NOT working
    override fun onInfoWindowClick(p0: Marker?) {
        Toast.makeText(
            activity, "Info window clicked",
            Toast.LENGTH_SHORT
        ).show()
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...