Scrolling ListView laggy because of calculating distance between locations
<p>I have a <code>ListView</code>, whose each entry showing some informations including the distance between the user's current location with the place of interest.</p>

<p>Unfortunately since I do the calculation of the distance inside the <code>getView()</code> (by calling the distance calculation method and returning the String to set the <code>TextView</code>) scrolling through the list is a bit laggy.</p>

<p>Can anybody give me a solution so I can have a smoother scrolling on my <code>ListView</code>?</p>

<p>Here's my <code>getView()</code> method:</p>

<pre><code>@Override
        public View getView(final int position, View convertView,
                ViewGroup parent) {
            layoutInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            FeedViewHolder feedViewHolder = null;
            final VideoLocationDB vidLocation = videoLocationsDB[position];
            String url = vidLocation.documentary_thumbnail_url;
            String name = vidLocation.name;
            String title = vidLocation.name;
            String desc = vidLocation.text;
            double lat = vidLocation.latitude;
            double lng = vidLocation.longitude;
            String distance = calculateDistance(lat,lng);


            if (convertView == null) {

                convertView = layoutInflater.inflate(R.layout.listitems, parent,false);
                feedViewHolder = new FeedViewHolder();
                feedViewHolder.titleView = (TextView) convertView.findViewById(R.id.txt_title);
                feedViewHolder.descView = (TextView) convertView.findViewById(R.id.txt_list_desc);
                feedViewHolder.more = (TextView) convertView.findViewById(R.id.txt_more);
                feedViewHolder.distanceView = (TextView) convertView.findViewById(R.id.txt_distance);
                feedViewHolder.v  = (ImageView) convertView.findViewById(R.id.image);

                Typeface fontRegular = Typeface.createFromAsset(getAssets(),
                        "miso.otf");
                feedViewHolder.titleView.setTypeface(fontRegular);
                Typeface fontLight = Typeface.createFromAsset(getAssets(),
                        "miso-light.otf");
                feedViewHolder.descView.setTypeface(fontLight);
                feedViewHolder.more.setTypeface(fontLight);
                feedViewHolder.distanceView.setTypeface(fontRegular);

                convertView.setTag(feedViewHolder);

            } else
            {
                feedViewHolder = (FeedViewHolder) convertView.getTag();
            }


            feedViewHolder.v.setTag(url);
            loader.DisplayImage(url, LocationsListActivity.this, feedViewHolder.v, name);
            feedViewHolder.titleView.setText(title.toUpperCase());
            feedViewHolder.descView.setText(desc);  
            feedViewHolder.more.setText(getString(R.string.de_list_more));
            feedViewHolder.distanceView.setText(distance);

            return convertView; 
        }
</code></pre>

<p>and here are the distance calculation methods:</p>

<pre><code>public double countDistance(double lat1, double lng1, double lat2,
            double lng2) {
        Location locationUser = new Location("point A");
        Location locationPlace = new Location("point B");
        locationUser.setLatitude(lat1);
        locationUser.setLongitude(lng1);
        locationPlace.setLatitude(lat2);
        locationPlace.setLongitude(lng2);

        double distance = locationUser.distanceTo(locationPlace);

        return distance;
    }

    public String calculateDistance(double lat2, double lng2){

        String distance = null;

        if (location != null) {
            double lat = location.getLatitude();
            double lng = location.getLongitude();

            if (countDistance(lat, lng, lat2, lng2) &gt;= 500) {
                double kilometer = countDistance(lat, lng, lat2, lng2) / 1000;
                int decimalPlaces = 1;
                BigDecimal decimal = new BigDecimal(kilometer);
                decimal = decimal.setScale(decimalPlaces,
                        BigDecimal.ROUND_HALF_UP);
                double new_km = decimal.doubleValue();
                distance = String.valueOf(new_km+ " km");
            } else {
                int decimalPlaces = 1;
                BigDecimal decimal = new BigDecimal(countDistance(lat, lng,
                        lat2, lng2));
                decimal = decimal.setScale(decimalPlaces,
                        BigDecimal.ROUND_HALF_UP);
                double meter = decimal.doubleValue();
                distance = String.valueOf(meter + " m");
            }
            videoLocationAdapter.notifyDataSetChanged();
        }
        return distance;
    }   
</code></pre>
