gpt4 book ai didi

android - 列表和 map 标记点击次数

转载 作者:搜寻专家 更新时间:2023-11-01 09:02:16 24 4
gpt4 key购买 nike

我有一个 Activity,左边有一个 ListFragment 和一个 SupportMapFragment在右边。

List 和 Map 都由相同的数据支持。 map 上数据的可视化表示是 Markers .

我希望能够在列表项标记上执行点击,并在其他视觉表示中获取相应的项目>.

框架和我的数据的限制是:

  1. Marker 类是最终的,Marker 的 id 没有修饰符。这就是为什么我不能使用最简单的方法。

  2. "It's important to not hold on to objects (e.g. Marker) beyond the view's life. Otherwise it will cause a memory leak as the view cannot be released." (see SupportMapFragment)

  3. 标记的标题可以出现多次。这就是为什么昂贵的字符串比较不是我可以采用的方式。

是否有人对此问题有可行的解决方案或可以向正确的方向提供帮助?

最佳答案

如果您希望能够注册对标记的点击,您需要覆盖 InfoWindowAdapter .

您可以为标记的标题和 fragment 提供独特的信息,并以这种方式实现接口(interface)的方法:

@Override
public View getInfoWindow(Marker marker) {
// do nothing here in order to obtain the original info window border.
return null;
}

@Override
public View getInfoContents(Marker marker) {
// Create your own view here. Obtain the unique information stored
// in title / snippet of the current marker.
return createdView;
}

现在您可以设置 OnInfoWindowClickListener并使用存储在那里的独特信息。

关于android - 列表和 map 标记点击次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14238366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com