gpt4 book ai didi

android - Google Maps v2 - 如何在 infowindowadapter 中填充两个以上的 TextView?

转载 作者:行者123 更新时间:2023-11-30 03:43:05 25 4
gpt4 key购买 nike

很惊讶我已经找不到答案了,但是我在使用 Google map 的信息窗口做一些非常简单的事情时遇到了问题。我想创建一个自定义信息窗口,其中包含三段文本,其中一段具有可自定义的颜色(取决于文本,但最好在放置标记时通过传入参数而不是设置此颜色)。这在 v1 中非常简单,但在 v2 中似乎完全搞砸了。

在我的主要 Activity 中,我有这一部分将我的自定义布局添加到 InfoWindowAdapter:

class MyInfoWindowAdapter implements InfoWindowAdapter{
private final View myContentsView;

MyInfoWindowAdapter(){
myContentsView = getLayoutInflater().inflate(R.layout.popup, null);
}

@Override
public View getInfoContents(Marker marker) {

TextView textStationName = (TextView) myContentsView.findViewById(R.id.textStationName);
textStationName.setText(marker.getTitle());

TextView textAPI = ((TextView)myContentsView.findViewById(R.id.textAPI));
textAPI.setText(marker.getSnippet());

return myContentsView;
}

@Override
public View getInfoWindow(Marker marker) {
// TODO Auto-generated method stub
return null;
}
}

我在创建标记时可以得到两条文本,“标题”和“fragment ”。但是我想在那里显示三段文字。到目前为止,我看到的所有示例都仅限于两段文本——无法获得第三个(或第四个……)元素。

我正在使用 v4 支持库(使用 API 版本 8)和操作指南 given here不幸的是,对我不起作用。

最佳答案

我建议将 map 标记的内容存储在 Map<Marker, InfoWindowContent 中在你的 Activity 中,InfoWindowContent是一些带有字段的类,用于填充标记的信息窗口。

将标记添加到 map 后,put带有信息窗口内容的标记到 Map .然后,在您的信息窗口内容适配器中,从 Map 获取标记的内容.

这是一个例子:

public class MyActivity extends Activity {

private static class InfoWindowContent {
public String text1;
public String text2;
public String text3;
// ... add other fields if you need them
}

private Map<Marker, InfoWindowContent> markersContent = new HashMap<Marker, InfoWindowContent>();

private void addMarker() {
Marker marker = map.addMarker(...);
InfoWindowContent markerContent = new InfoWindowContent();
// ... populate content for the marker

markersContent.put(marker, markerContent);
}

class MyInfoWindowAdapter implements InfoWindowAdapter {

@Override
public View getInfoContents(Marker marker) {
InfoWindowContent markerContent = markersContent.get(marker);

// ... populate info window with your content
}
}
}

关于android - Google Maps v2 - 如何在 infowindowadapter 中填充两个以上的 TextView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15438724/

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