我想實現一個Google地圖標記與infoWindow,如果有人點擊這個infoWindow,它播放歌曲,如果再次點擊,它會停止。爲了想象這個,我寫了一個自定義的infoWindow佈局。在infoWindow中,您可以通過按鈕查看用戶和跟蹤信息。如果曲目還沒有開始播放,此按鈕顯示播放圖標,如果按下(按下infoWindow,而不是按鈕),我希望它將其圖標從「播放」更改爲「停止」。不過,根據infoWindowClickListener活動,我無法更改自定義infoWindow的視圖。我試圖更改infoWindowAdapter,但我不想更改所有其他infoWindows的視圖,也想立即查看更改。這樣,當我再次點擊標記後,infoWindow刷新它的視圖。換句話說,它不會與我的點擊操作同時改變視圖。更改infoWindow視圖取決於點擊監聽器
在這裏你可以看到我在說什麼。停止狀態在左邊,右邊播放狀態:
這裏是我的適配器徒勞的努力:
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;
}
}
如果你需要更多的信息來清楚地瞭解問題,請問我。
好看的佈局 – peresisUser