如何将内容更新到InfoWindowAdapter?

时间:2014-10-15 13:10:07

标签: android xml android-layout infowindow

大家好我有一个InfoWindowAdapter,其中包含自定义内容(图片和一些文字视图)。我使用Picasso Library从Web或缓存加载图像,但因为它需要0.5秒。和InfoWindowAdapter不会自动刷新其内容我该如何做"刷新"它的内容??这是我为以下代码制作的代码:

map.setInfoWindowAdapter(new InfoWindowAdapter() {

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


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

@Override
public View getInfoContents(Marker marker) {
/* Distanza a piedi e macchina sulla nuvoletta */
/***********************************************/

    GPSTracker gpsTracker = new GPSTracker(MainActivity.this);

    if (gpsTracker.canGetLocation())
    {
        String stringLatitude = String.valueOf(gpsTracker.latitude);
        String stringLongitude = String.valueOf(gpsTracker.longitude);

        double currentLat = Double.parseDouble(stringLatitude);
        double currentLng = Double.parseDouble(stringLongitude);

        double destLat = marker.getPosition().latitude;
        double destLng = marker.getPosition().longitude;

        final float[] results = new float[3];
        Location.distanceBetween(currentLat, currentLng, destLat, destLng, results);

        float metri = results[0];
        float km = Math.round((double)metri/1000);

        int minuti_persona = (int)Math.round(metri/125);    //125 metri al minuto -> velocità media di 2,5 m/s
        int minuti_auto = (int)Math.round(km/0.7);          //700 metri al minuto -> velocità media di 42 km/h 


        /***********************************************/



        TextView tvTitle = (TextView) v.findViewById(R.id.title);
        TextView tvSnippet = (TextView) v.findViewById(R.id.snippet);
        tvSnippet.setTypeface(tvSnippet.getTypeface(), Typeface.ITALIC); //indirizzo in corsivo
        TextView tvPedonal_distance = (TextView) v.findViewById(R.id.pedonal_time);
        TextView tvCar_distance = (TextView) v.findViewById(R.id.car_time);
        tvTitle.setText(marker.getTitle());
        tvSnippet.setText(marker.getSnippet());

        if(minuti_persona <=0)          // Stampa tempo per coprire la distanza
        {
            tvCar_distance.setText("A piedi: meno di un minuto");
        }else
        {
            tvPedonal_distance.setText("A piedi: "+minuti_persona+ " minuti");
        }

        if(minuti_auto <= 0)
        {
            tvCar_distance.setText("In auto: meno di un minuto");                                   
        }else
        {
            tvCar_distance.setText("In auto: " +minuti_auto+ " minuti");
        }


        //Prova immagine custom
        /***********************************/

        ImageView image;
        String currentUrl="http://upload.wikimedia.org/wikipedia/commons/5/50/Casa_Natale_Benito_Mussolini_(1).jpg";
        image = (ImageView) v.findViewById(R.id.image_nuvoletta);

        Picasso.with(v.getContext())
            .load(currentUrl)
            .error(R.drawable.ic_launcher)  //in caso di errore fa vedere questa immagine (un triangolo penserei)
            .resize(150, 110)
            .into(image, new Callback(){

        @Override
        public void onSuccess(){
            //where I have to update my InfoWindow

        }

        @Override
        public void onError(){

        }
}); 

return v;

InfoWindowAdapter XML:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center_horizontal|left"
    android:background="#FFFFFF"
    android:orientation="horizontal">

    <ImageView
        android:id="@+id/image_nuvoletta"
        android:layout_width="90dp"
        android:layout_height="60dp"
        android:layout_marginRight="5dp"
        android:layout_marginLeft="0dp"
        android:layout_gravity="left|fill"
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher"/>

        <LinearLayout
            android:layout_width="wrap_content"
            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="12dp"
                android:textStyle="bold"/>

            <TextView
                android:id="@+id/snippet"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="10dp"/>

            <LinearLayout 
                android:id="@+id/distanceinfo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView 
                    android:id="@+id/pedonal_time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="10dp"/>

                <TextView 
                    android:id="@+id/car_time"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="10dp"/>

            </LinearLayout>

        </LinearLayout>

</LinearLayout>

0 个答案:

没有答案