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 8012417
In Process

The Archive Base Latest Questions

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

I’m using ArrayAdapter for my ListView , at the firs time everything’s displayed correctly,

  • 0

I’m using ArrayAdapter for my ListView, at the firs time everything’s displayed correctly, the problem was just the ListView is laggy when I scroll through it.
So I found a solution by using ViewHolder, and finally my ListView can be scrolled smoothly but there’s a drawback, the items on my ListView got mixed up.

How can I fix that?

Here’s my getView() method for my ArrayAdapter:

public class VideoLocationAdapter extends ArrayAdapter<VideoLocationDB> {
        public ImageLoader imageLoader;
        ImageLoader loader = null;

        public VideoLocationAdapter(Context context, int resource,
                VideoLocationDB[] videoLocationDBs) {
            super(context, resource, videoLocationDBs);
            loader = new ImageLoader(context);
        }

        private LayoutInflater layoutInflator;

        @Override
        public View getView(final int position, View convertView,
                ViewGroup parent) {

            FeedViewHolder feedViewHolder;

            if (convertView == null) {

                convertView = LocationsListActivity.this.getLayoutInflater()
                        .inflate(R.layout.listitems, null, true);

                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);

                final VideoLocationDB vidLocation = videoLocationsDB[position];

                // Image
                String url = vidLocation.documentary_thumbnail_url;
                String name = vidLocation.name;
                feedViewHolder.v.setTag(url);

                loader.DisplayImage(url, LocationsListActivity.this, feedViewHolder.v, name);

                // Title        
                String title = vidLocation.name;
                feedViewHolder.titleView.setText(title.toUpperCase());
                Typeface fontRegular = Typeface.createFromAsset(getAssets(),
                        "miso.otf");
                feedViewHolder.titleView.setTypeface(fontRegular);

                // Description          
                String desc = vidLocation.text;
                feedViewHolder.descView.setText(desc);
                Typeface fontLight = Typeface.createFromAsset(getAssets(),
                        "miso-light.otf");
                feedViewHolder.descView.setTypeface(fontLight);

                // More     
                feedViewHolder.more.setText(getString(R.string.de_list_more));
                feedViewHolder.more.setTypeface(fontLight);

                // Distance
                feedViewHolder.distanceView.setTypeface(fontRegular);

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

                    double lat2 = roundDown(vidLocation.latitude);
                    double lng2 = roundDown(vidLocation.longitude);

                    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();
                        feedViewHolder.distanceView.setText(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();
                        feedViewHolder.distanceView.setText(meter + " m");
                    }
                    videoLocationAdapter.notifyDataSetChanged();
                }

                convertView.setTag(feedViewHolder);

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

static class FeedViewHolder{

        TextView titleView;
        TextView descView;
        TextView more;
        TextView distanceView;
        ImageView v;
    }
  • 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:19:36+00:00Added an answer on June 4, 2026 at 7:19 pm

    you have the set the text out side/after the if if (convertView == null) {} and else

    if (convertView == null) {
    //create the view
    }else {
    //get the view from convertView
    }

    here set the text in views

    look

    http://android.amberfog.com/?p=296

    @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                System.out.println("getView " + position + " " + convertView);
                ViewHolder holder = null;
                if (convertView == null) {
                    convertView = mInflater.inflate(R.layout.item1, null);
                    holder = new ViewHolder();
                    holder.textView = (TextView)convertView.findViewById(R.id.text);
                    convertView.setTag(holder);
                } else {
                    holder = (ViewHolder)convertView.getTag();
                }
    
             holder.textView.setText(mData.get(position));//<========== see it .....
                return convertView;
            }
    
        }
    

    Put this code after if/else

     final VideoLocationDB vidLocation = videoLocationsDB[position];
    
                    // Image
                    String url = vidLocation.documentary_thumbnail_url;
                    String name = vidLocation.name;
                    feedViewHolder.v.setTag(url);
    
                    loader.DisplayImage(url, LocationsListActivity.this, feedViewHolder.v, name);
    
                    // Title        
                    String title = vidLocation.name;
                    feedViewHolder.titleView.setText(title.toUpperCase());
                    Typeface fontRegular = Typeface.createFromAsset(getAssets(),
                            "miso.otf");
                    feedViewHolder.titleView.setTypeface(fontRegular);
    
                    // Description          
                    String desc = vidLocation.text;
                    feedViewHolder.descView.setText(desc);
                    Typeface fontLight = Typeface.createFromAsset(getAssets(),
                            "miso-light.otf");
                    feedViewHolder.descView.setTypeface(fontLight);
    
                    // More     
                    feedViewHolder.more.setText(getString(R.string.de_list_more));
                    feedViewHolder.more.setTypeface(fontLight);
    
                    // Distance
                    feedViewHolder.distanceView.setTypeface(fontRegular);
    
                    if (location != null) {
                        double lat = location.getLatitude();
                        double lng = location.getLongitude();
    
                        double lat2 = roundDown(vidLocation.latitude);
                        double lng2 = roundDown(vidLocation.longitude);
    
                        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();
                            feedViewHolder.distanceView.setText(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();
                            feedViewHolder.distanceView.setText(meter + " m");
                        }
                        videoLocationAdapter.notifyDataSetChanged();
                    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.