Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8013531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:39:24+00:00 2026-06-04T19:39:24+00:00

I have a ListView , whose each entry showing some informations including the distance

  • 0

I have a ListView, whose each entry showing some informations including the distance between the user’s current location with the place of interest.

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

Can anybody give me a solution so I can have a smoother scrolling on my ListView?

Here’s my getView() method:

@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; 
        }

and here are the distance calculation methods:

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) >= 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;
    }   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:39:26+00:00Added an answer on June 4, 2026 at 7:39 pm

    Greendroid (https://github.com/cyrilmottier/GreenDroid) is using Future (http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Future.html) to load asynchronously images from the web in a list view. And it’s very very efficient, even when the list contains hundred of entries. So I think this is the kind of things you’re looking for. The futures are managed by an executor that handles a pool so that everything is done within your hardware limits.

    Some code ? Greendroid and there is an interesting example here where you could find more information. It was in my bookmark but I don’t know if it’s up to date:
    http://blog.tomgibara.com/post/7665158012/android-adapter-view-rendering

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView whose rows are formatted by me. Each row has a
I have a ListView whose ItemsSource is bound to an ObservableCollection. The collection is
I have a ListView whose size is fixed to maximum of 10 items View
In my application, I have a listview whose list item consists of a TextView
I have listview control.There is an option to remove selected items.After the user removes
I have listview having customized some textview and one imageview. When I long click
I have a ListView that inflate for each row a xml that contain a
I have a listview whose rows has one textview and a check box. I
I have a ListView in which each item has a complex layout that contains,
I have a List and each entry has a dynamic count of attributes which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.