设置可点击的谷歌地图标记的标题

时间:2019-01-28 10:03:18

标签: android google-maps kotlin marker

我已经为我的Android应用创建了自定义 InfoWindow 。运行正常,我可以在其中看到自定义数据。

我想知道如何使标题和整个内容一次可点击吗?

我正在生成一些数据并显示它们,我希望能够单击要创建的每个textView。

我已经看到标记的行为类似于图像,这是一种避免这种情况的方法(当我单击标题时,单击了孔块)

查看我的InfoWindo:

class InfoWindowCustom(internal var context: Context, internal var mMap: GoogleMap, internal val idItem: String, internal val listeArrets: JSONArray, internal val name : String) : GoogleMap.InfoWindowAdapter {

    internal lateinit var inflater: LayoutInflater
    private val TAG = InfoWindowCustom::class.java.simpleName
    /* some variables ...*/
    override fun getInfoContents(marker: Marker): View? {
        return null
    }

    override fun getInfoWindow(marker: Marker): View {
        inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
        val v = inflater.inflate(R.layout.custom_info_window, null)

        val title = v.findViewById<TextView>(R.id.title)
        title.text = name
        val loader = v.findViewById<TextView>(R.id.loadingArretProxi)
        Log.i("Proximite", "$name infoWindow")
        if(listeArrets.length() > 0){
            loader.visibility = View.GONE
            (0 until listeArrets.length()).forEach   {
                val item = listeArrets.getJSONObject(it)
                val code = item.getString("code")

                val linearLayoutRes = v.findViewById<LinearLayout>(R.id.resMarkerHoraire)
                val linearLayoutResultArret = LinearLayout(this.context)
                linearLayoutResultArret.layoutParams = lpmm
                linearLayoutResultArret.setPadding(30,15,15,15)
                linearLayoutResultArret.setBackgroundColor(colorWhite)
                linearLayoutResultArret.weightSum = 1F
                linearLayoutResultArret.orientation = LinearLayout.HORIZONTAL
                linearLayoutRes.addView(linearLayoutResultArret)

                val ligne = TextView(this.context)
                lpww.weight = 0.1F
                ligne.layoutParams = lpww
                ligne.text = code
                ligne.textAlignment = TextView.TEXT_ALIGNMENT_CENTER
                ligne.background = lignea
                ligne.setTextColor(colorBlack)
            }
        }



        mMap.setOnInfoWindowClickListener {
            val bundle = Bundle()
            bundle.putString("datafirst", idItem)
            bundle.putString("datasecond", marker.title)

            val fragment = Result()
            fragment.arguments = bundle
            val fragmentManager = (context as AppCompatActivity).supportFragmentManager
            val fragmentTransaction = fragmentManager.beginTransaction()

            fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack(null)
            fragmentTransaction.commit()
        }

        return v
    }
}

0 个答案:

没有答案
相关问题