gpt4 book ai didi

android - 单击标记时清空信息窗口

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:24:20 24 4
gpt4 key购买 nike

这是我将新标记添加到我的 GoogleMap 的代码:

MarkerOptions m = new MarkerOptions();
m.title(title);
m.snippet(snippet);
m.position(location);
mMap.addMarker(m);

mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Toast.makeText(DemoActivity.this, "WindowClicked: "+ marker.getTitle() + ":" + marker.getSnippet(),
Toast.LENGTH_SHORT).show();
}
});

现在,当我的 titlesnippet 是英文时,这就很好用了。 infoWindowToast 按预期工作。

但是,就我而言,titlesnippet 是阿拉伯语,Toast 工作正常但 InfoWindow 显示空窗口

在我看来,这像是与阿拉伯语相关的错误。有解决办法吗?

最佳答案

@jimmithy 的回答解决了我的问题。

这只是来自 this project三步实现 :

第 1 步:创建信息窗口的布局。这是 popup.xml 代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:padding="2dip"
android:src="@drawable/ic_launcher"
android:contentDescription="@string/icon"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:textStyle="bold"/>

<TextView
android:id="@+id/snippet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="15sp"/>
</LinearLayout>

</LinearLayout>

第 2 步:创建您的 InfoWindowAdapter 实现。这是 PopupAdapter 类:

class PopupAdapter implements InfoWindowAdapter {
LayoutInflater inflater=null;

PopupAdapter(LayoutInflater inflater) {
this.inflater=inflater;
}

@Override
public View getInfoWindow(Marker marker) {
return(null);
}

@Override
public View getInfoContents(Marker marker) {
View popup=inflater.inflate(R.layout.popup, null);

TextView tv=(TextView)popup.findViewById(R.id.title);

tv.setText(marker.getTitle());
tv=(TextView)popup.findViewById(R.id.snippet);
tv.setText(marker.getSnippet());

return(popup);
}
}

第 3 步:在您的 Activity 中,将您的适配器设置为 GoogleMap:

mMap.setInfoWindowAdapter(new PopupAdapter(getLayoutInflater()));

你已经准备好了!

关于android - 单击标记时清空信息窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17689311/

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