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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:52:07+00:00 2026-06-15T10:52:07+00:00

Hello Stack Overflow Android Users, Please help with the following question: Problem I’m writing

  • 0

Hello Stack Overflow Android Users,

Please help with the following question:

Problem

I’m writing an a feature for an app that lists species of fish.
I’m using a custom ListView Adapter class (let’s call this FishSpeciesListAdapter) for the adapter. I have 27 fish species
recorded as a default for the program as for now (you will eventually be able to add
some yourself as well). The problem is that when I link the adapter to the actual listview xml object, it seems to iterate over the same 5-6 species all the time.

The problem must lie within the custom adapter because I’ve tested the recorded species and all species are different within a List that I pass to the adapter.

Here’s the code where I set the adapter:

this.n_fishSpeciesListView = FindViewById<ListView> (Resource.Id.xml_fishSpeciesListView);
this.n_fishSpeciesListView.Adapter = new FishSpeciesListAdapter (this, 
this.n_model.SpecieManager.Species);

Here’s the Custom ListView Adapter code:

public class FishSpeciesListAdapter : BaseAdapter
{
    Context n_context;
    List<AppCode.Specie> n_specieData;

    public FishSpeciesListAdapter (Context context, List<AppCode.Specie> specieData)
    {
        this.n_context = context;
        this.n_specieData = specieData;
    }

    public override int Count {
        get { return this.n_specieData.Count; }
    }

    public override Java.Lang.Object GetItem (int position)
    {
        return null;
    }

    public override long GetItemId (int position)
    {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public override View GetView (int position, View convertView, ViewGroup parent)
    {
        View v;
        if(convertView==null){

            LayoutInflater li = LayoutInflater.FromContext(parent.Context);
            v = li.Inflate(Resource.Layout.Adapter_FishSpeciesIcon, null);
            ImageView iconImage = (ImageView)v.FindViewById(Resource.Id.xml_adapter_fishSpeciesIconImage);
            TextView nameText = (TextView)v.FindViewById(Resource.Id.xml_adapter_fishSpeciesNameText);
            TextView scientificNameText = (TextView)v.FindViewById(Resource.Id.xml_adapter_fishSpeciesScientificNameText);

            nameText.Text = this.n_specieData[position].Name;
            scientificNameText.Text = this.n_specieData[position].ScientificName;

            if (this.n_specieData[position].RelatedMedia.AttachedPhotos.Count < 1)
            {
                iconImage.SetImageResource(Resource.Drawable.Icon); 
            }
            else
            {
                iconImage.SetImageBitmap(BitmapFactory.DecodeByteArray(this.n_specieData[position].RelatedMedia.AttachedPhotos[0], 0, this.n_specieData[position].RelatedMedia.AttachedPhotos[0].Length));  
            }   
        }
        else
        {
            v = convertView;
        }
        return v;
    }
}

So when I execute the above code, here’s a screenshot of what I get:

Items Repeat themselves when there should be 27 unique species here, of course this isnt the whole list but an example where you can see the looping happen!

As you can see there are duplicates where I’m am positive that there are at least 27 different species recorded in the passed List variable. Any help as to why this is and how I can fix this would be very helpful.

My Research

I’ve read that it may be reusing the “View currentView” variable in the GetView method of the adapter. I found that information out in this link. I just don’t know how to fix this in my case. Code examples would be nice or detailed directions. Thank you for your time.

  • 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-15T10:52:08+00:00Added an answer on June 15, 2026 at 10:52 am

    From what I see, you’re using the convertView object wrong. This object is available in case any Views have been recycled (for example a list item scrolled out of view). It is available so that you don’t have to inflate from your layout xml again (which is a costly process).

    What you should do is inflate from your layout xml if convertView==null. Otherwise use the convertView object.

     if(convertView==null){
    
            LayoutInflater li = LayoutInflater.FromContext(parent.Context);
            v = li.Inflate(Resource.Layout.Adapter_FishSpeciesIcon, null);
    }
    else{
         v=convertView;
    }
    

    Then use v to set all your values and return the View.

        ImageView iconImage = (ImageView)v.FindViewById(Resource.Id.xml_adapter_fishSpeciesIconImage);
            TextView nameText = (TextView)v.FindViewById(Resource.Id.xml_adapter_fishSpeciesNameText);
            TextView scientificNameText = (TextView)v.FindViewById(Resource.Id.xml_adapter_fishSpeciesScientificNameText);
    
     nameText.Text = this.n_specieData[position].Name;
     scientificNameText.Text = this.n_specieData[position].ScientificName;
    
     if (this.n_specieData[position].RelatedMedia.AttachedPhotos.Count < 1)
     {
           iconImage.SetImageResource(Resource.Drawable.Icon); 
     }
     else
     {
           iconImage.SetImageBitmap(BitmapFactory.DecodeByteArray(this.n_specieData[position].RelatedMedia.AttachedPhotos[0], 0, this.n_specieData[position].RelatedMedia.AttachedPhotos[0].Length));  
     }   
     return v;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Stack Overflow users, I have a fun problem that I have in my
Hello there Stack Overflow, I hope you'll help me with my very first question
Hello stack overflow I need help with this problem. Ok, I have a flat
First off - hello, this is my first Stack Overflow question so I'll try
Hello there people of stack overflow, I have just started developing with android and
Hello again Stack Overflow. you probably remember me from my unit spawning problem in
Hello good Stack Overflow people, I do have a business problem and would like
Using Stack Overflow question How to send an object from one Android Activity to
The tutoriel in question is http://developer.android.com/resources/tutorials/views/hello-gridview.html The Tutorial asks that you 1- Create a
Why the following code issues an error ? ['hello','stack','overflow'].inject{|memo,s|memo+s.length} TypeError: can't convert Fixnum into

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.