3

マップのウィンドウ情報のカスタム レイアウトがありますが、マーカーからデータを渡す方法の例が見当たりません。

誰でも助けることができますか?

mMap.setInfoWindowAdapter(new InfoWindowAdapter() {

    // Use default InfoWindow frame
    @Override
    public View getInfoWindow(Marker arg0) {
        return null;
    }

    @Override
    public View getInfoContents(Marker arg0) {

        View v = getActivity().getLayoutInflater().inflate(R.layout.info_window_layout, null); 

        ImageView pic = (ImageView) v.findViewById(R.id.pic); 
        String url = <????>;
        // set pic image from url

        TextView name = (TextView) v.findViewById(R.id.name); 
        name.setText(<????>);

        TextView address = (TextView) v.findViewById(R.id.address); 
        address.setText(<????>);

        return v;

    }
});

mCenterList = MyApplication.dbHelper.getAllCenter();

for(Center center : mCenterList){

    Marker marker = mMap.addMarker(
            new MarkerOptions().position(new LatLng(center.lat, center.lng))
            .icon(BitmapDescriptorFactory.fromResource(R.drawable.elipin)));                

    // How can I pass custom data, here pic, name and address, to the marker, to
    // make it available in getInfoContents?


}

info_window_layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="300dp"
    android:layout_height="50dp"
    android:padding="5dp" >

    <ImageView
        android:id="@+id/pic"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_marginRight="5dp"
        android:scaleType="centerCrop" />

    <ImageView
        android:id="@+id/arrow"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_alignParentRight="true"
        android:layout_marginLeft="5dp"
        android:scaleType="centerCrop"
        android:src="@drawable/arrowri" />

    <TextView
        android:id="@+id/name"
        android:layout_width="match_parent"
        android:layout_height="25dp"
        android:layout_toRightOf="@id/pic"
        android:layout_toLeftOf="@id/arrow"
        android:gravity="center_vertical"
        android:singleLine="true"
        android:textColor="#ffffff"
        android:textSize="18sp" />

    <TextView
        android:id="@+id/address"
        android:layout_width="match_parent"
        android:layout_height="15dp"
        android:layout_toRightOf="@id/pic"
        android:layout_toLeftOf="@id/arrow"
        android:layout_below="@id/name"
        android:gravity="center_vertical"
        android:singleLine="true"
        android:textColor="#ffffff"
        android:textSize="16sp" />

</RelativeLayout>
4

5 に答える 5

5

Markerisであるためfinal、そこからサブクラスを作成することはできません。

したがって、私が見つけた最善の解決策はMarker、スニペットなどの何かを使用して、追加のデータを検索できるキーを保持することです。たとえば、HashMapデータ モデルのキーであったり、データベースの主キーであったりします。

次に、あなた<????>は直接からではなく、2 つを結び付ける識別情報を持っているMarker実際のデータ モデルから来ます。Marker

于 2013-04-19T15:31:26.187 に答える
0

このライブラリAndroid Maps Extentionsを見つけ、プロジェクトで使用しました。これは便利で、データをウィンドウに簡単に渡すのに役立ちます。

ありがとう、

于 2013-04-30T04:14:25.720 に答える
-1

以下の方法

mMap.setOnMarkerClickListener(新しいOnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(**Marker arg0**) { } 

値を渡すのに役立ちます。

つまり、 Marker パラメータは、1、2、3 などのマーカー数を返します。

この番号を arraylist.get(1).details のように渡すと、対応する詳細を取得できます

リストから

于 2013-04-19T18:30:02.940 に答える