public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = convertView;

            // Reuse an existing view, if one is available, otherwise create a new one
            if (view == null)
            {
                view = context.LayoutInflater.Inflate(Resource.Layout.POIListItem, null, false);
            }

            PointOfInterest poi = this [position];

            view.FindViewById <TextView>(Resource.Id.nameTextView).Text = poi.Name;

            if (String.IsNullOrEmpty(poi.Address))
            {
                view.FindViewById <TextView>(Resource.Id.addrTextView).Visibility = ViewStates.Gone;
            }
            else
            {
                view.FindViewById <TextView>(Resource.Id.addrTextView).Text = poi.Address;
            }

            var imageView = view.FindViewById <ImageView>(Resource.Id.poiImageView);

            if (!String.IsNullOrEmpty(poi.Address))
            {
                Koush.UrlImageViewHelper.SetUrlDrawable(imageView, poi.Image, Resource.Drawable.ic_placeholder);
            }

            var distanceTextView = view.FindViewById <TextView>(Resource.Id.distanceTextView);

            if ((CurrentLocation != null) && (poi.Latitude.HasValue) && (poi.Longitude.HasValue))
            {
                Location poiLocation = new Location("");
                poiLocation.Latitude  = poi.Latitude.Value;
                poiLocation.Longitude = poi.Longitude.Value;
                float distance = CurrentLocation.DistanceTo(poiLocation) * 0.000621371F;
                distanceTextView.Text = String.Format("{0:0,0.00}  miles", distance);
            }
            else
            {
                distanceTextView.Text = "??";
            }


            return(view);
        }
Beispiel #2
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View view = convertView;

            if (view == null)
            {
                view = _context.LayoutInflater.Inflate(Resource.Layout.POIListItem, null);
            }

            PointOfInterest poi = POIData.Service.POIs [position];

            //load image into image view
            Bitmap poiImage = POIData.GetImageFile(poi.Id.Value);

            view.FindViewById <ImageView> (Resource.Id.poiImageView).SetImageBitmap(poiImage);
            if (poiImage != null)
            {
                poiImage.Dispose();
            }
            view.FindViewById <TextView> (Resource.Id.nameTextView).Text = poi.Name;

            if (string.IsNullOrEmpty(poi.Address))
            {
                view.FindViewById <TextView> (Resource.Id.addrTextView).Visibility = ViewStates.Gone;
            }
            else
            {
                view.FindViewById <TextView> (Resource.Id.addrTextView).Text = poi.Address;
            }

            if ((CurrentLocation != null) && (poi.Latitude.HasValue) && (poi.Longitude.HasValue))
            {
                Location poiLocation = new Location("");
                poiLocation.Latitude  = poi.Latitude.Value;
                poiLocation.Longitude = poi.Longitude.Value;
                float distance = CurrentLocation.DistanceTo(poiLocation) / 1000;                  //原單位為公尺;若乘以 0.000621371F表以英哩顯示;
                view.FindViewById <TextView> (Resource.Id.distanceTextView).Text =
                    String.Format("{0:0,0.00} 公里", distance);
            }
            else
            {
                view.FindViewById <TextView> (Resource.Id.distanceTextView).Text = "??";
            }

            return(view);
        }
Beispiel #3
0
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var view = convertView;

            if (view == null)
            {
                view = _context.LayoutInflater.Inflate(Resource.Layout.POIListItem, null);
            }

            var poi = POIData.Service.POIs[position];

            view.FindViewById <TextView>(Resource.Id.nameTextView).Text = poi.Name;
            if (string.IsNullOrWhiteSpace(poi.Address))
            {
                view.FindViewById <TextView>(Resource.Id.addressTextView).Visibility = ViewStates.Gone;
            }
            else
            {
                view.FindViewById <TextView>(Resource.Id.addressTextView).Text = poi.Address;
            }

            if (CurrentLocation != null && poi.Latitude.HasValue && poi.Longitude.HasValue)
            {
                var poiLocation = new Location(String.Empty);
                poiLocation.Latitude  = poi.Latitude.Value;
                poiLocation.Longitude = poi.Longitude.Value;
                float distance = CurrentLocation.DistanceTo(poiLocation) * 0.000621371F; // this magic number converts from meters to miles

                view.FindViewById <TextView>(Resource.Id.distanceTextView).Text = String.Format("{0:0,0.00} miles", distance);
            }
            else
            {
                view.FindViewById <TextView>(Resource.Id.distanceTextView).Text = "??";
            }

            var poiImage = POIData.GetImageFile(poi.Id.Value);

            view.FindViewById <ImageView>(Resource.Id.poiImageView).SetImageBitmap(poiImage);
            if (poiImage != null)
            {
                poiImage.Dispose();
            }

            return(view);
        }