gpt4 book ai didi

android - 根据点击监听器更改 infoWindow View

转载 作者:行者123 更新时间:2023-11-29 01:33:23 24 4
gpt4 key购买 nike

我正在尝试使用 infoWindow 实现一个 Google map 标记,如果有人点击此 infoWindow,它会播放一首歌曲,如果再次点击,它会停止。为了形象化这一点,我编写了一个自定义信息窗口布局。在 infoWindow 中,您可以使用按钮查看用户和跟踪信息。如果轨道还没有开始播放,这个按钮会显示播放图标,如果它按下了(按下信息窗口,而不是按钮),我希望它将它的图标从“播放”更改为“停止”。但是,我无法根据 infoWindowClickListener Activity 更改自定义 infoWindow 的 View 。我试图特别更改 infoWindowAdapter,但我不想更改所有其他 infoWindows 的 View ,而且我想立即看到更改。这样,当我再次点击标记后,infoWindow 会刷新它的 View 。换句话说,它不会与我的点击操作同时更改 View 。

在这里你可以明白我在说什么。左边停止状态,右边播放状态:

enter image description here

这是我为适配器所做的徒劳努力:

public class OrangeInfoWindowAdapter implements GoogleMap.InfoWindowAdapter {

Context context;
ImageButton playButton;
boolean onPlay;

public OrangeInfoWindowAdapter(Context context, boolean onPlay) {
this.context = context;
this.onPlay = onPlay;
}

@Override
public View getInfoWindow(Marker arg0) {

LayoutInflater inflater = LayoutInflater.from(context);
View v = inflater.inflate(R.layout.orange_infowindow, null);

v.setMinimumWidth(280);
v.setMinimumHeight(120);

TextView tvUsername = (TextView) v.findViewById(R.id.tv_username);
TextView tvTrack = (TextView) v.findViewById(R.id.tv_track);

int index = arg0.getTitle().indexOf("*");

try {
tvUsername.setText(arg0.getTitle().substring(0, index - 1) + "\n" + arg0.getTitle().substring(index + 2));
} catch (StringIndexOutOfBoundsException e) {
}

tvUsername.setTextSize(10);
tvUsername.setTextColor(Color.rgb(70, 70, 70));

index = arg0.getSnippet().indexOf("*");

try {
tvTrack.setText(arg0.getSnippet().substring(0, index - 1) + "\n" + arg0.getSnippet().substring(index + 2));
} catch (StringIndexOutOfBoundsException e) {
}

tvTrack.setTextSize(10);
tvTrack.setTextColor(Color.rgb(230, 92, 1));

playButton = (ImageButton) v.findViewById(R.id.playButton);

if (onPlay)
onPlay();

return v;

}

public void onPlay() {
playButton.setBackgroundResource(R.drawable.info_stop_button);
}

public void onStop() {
playButton.setBackgroundResource(R.drawable.info_play_button);
}

@Override
public View getInfoContents(Marker arg0) {
return null;
}
}

这是我的 onInfoWindowClick():

@Override
public void onInfoWindowClick(Marker marker) {
if (!infoWindowPlayerActive) {
int index = findMarkerIndex(marker);
OrangeInfoWindowAdapter infoWindowAdapter2 = new OrangeInfoWindowAdapter(getActivity().getApplicationContext(), true);
googleMap.setInfoWindowAdapter(infoWindowAdapter2);
new InfoWindowPlayerTask(mainActivity).execute(activities.get(index).getTrackId());
infoWindowPlayerActive = true;
}

else {
// same thing...
infoWindowPlayerActive = false;
}
}

如果您想了解更多信息以清楚地了解问题,请问我。

最佳答案

The GoogleMap API v.2 does not support any interaction on InfoWindow, besides opening and closing it.

然而,有一个惊人的黑客实现 in this answer ,关于您应该如何在 InfoWindow 中创建交互式 View 。请记住,同样的技术也适用于 fragment 。

来自official documentation :

Note: The info window that is drawn is not a live view. The view is rendered as an image (using View.draw(Canvas)) at the time it is returned. This means that any subsequent changes to the view will not be reflected by the info window on the map. To update the info window later (e.g., after an image has loaded), call showInfoWindow(). Furthermore, the info window will not respect any of the interactivity typical for a normal view such as touch or gesture events. However you can listen to a generic click event on the whole info window as described in the section below.

关于android - 根据点击监听器更改 infoWindow View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30014690/

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