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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:18:57+00:00 2026-06-01T06:18:57+00:00

This post will be heavy on images. I have created a custom ArrayAdapter and

  • 0

This post will be heavy on images.

I have created a custom ArrayAdapter and using it on a Listview. Am I missing something here on the Adapter?

   @Override
   public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      ArrayHolder holder = null;

      if(row == null)
      {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);
        holder = new ArrayHolder();
        holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
        row.setTag(holder);
     }
     else
     {
        if(position % 2 == 0){row.setBackgroundColor(Color.DKGRAY);}
        else{row.setBackgroundColor(Color.BLACK);}

        Typeface font1 =Typeface.createFromAsset(context.getAssets(),"fonts/kingrich.ttf");
        ((TextView)row.findViewById(R.id.txtTitle)).setTypeface(font1);
        ((TextView)row.findViewById(R.id.txtTitle)).setTextColor(Color.rgb(153, 255, 102));

        holder = (ArrayHolder)row.getTag();

    }

    String array = data.get(position);
    holder.txtTitle.setText(array);
    return row;
  }

When I first launch the application, the following screen is displayed:
(Screens are form an actual device and not an emulator)

After app is initialized

Now if I close the virtual keyboard with the back button, on the bottom I can already see one row now being colored incorrectly, when I scroll down a little:

Scroll down a little to see the “bad” row

If I scroll up and down, the row will get the coloring correct.

Thanks in advance

  • 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-01T06:18:59+00:00Added an answer on June 1, 2026 at 6:18 am

    It looks to me that you are not handling correctly the creation of new views.

    The text appears as white, this tells us that the else block is skipped (so the convertView parameter was null, or that there are no views to recycle (which is fair, since you see many more views when the softkeyboard disappears)

    The row gets colored correctly after a scroll up/down because you now have views to recycle and therefore you will enter the else block.

    Imho you should remove altogether the else keyword.
    This way you will enter the if (where you create the new view) only if there is actually the need, but otherwise you will always put the correct color even if the view is new and not recycled.

    Give it a try and tell me if it works

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      View row = convertView;
      ArrayHolder holder = null;
    
      if(row == null)
      {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);
        holder = new ArrayHolder();
        holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
        row.setTag(holder);
     }
    //this part must be executed every time, not only for recycled views
      if(position % 2 == 0){row.setBackgroundColor(Color.DKGRAY);}
      else{row.setBackgroundColor(Color.BLACK);}
    
      Typeface font1 = Typeface.createFromAsset(context.getAssets(),   "fonts/kingrich.ttf");
      ((TextView)row.findViewById(R.id.txtTitle)).setTypeface(font1);
      ((TextView)row.findViewById(R.id.txtTitle)).setTextColor(Color.rgb(153, 255, 102));
    
      holder = (ArrayHolder)row.getTag();
    
    
    
      String array = data.get(position);
      holder.txtTitle.setText(array);
      return row;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which will post a message on a friends wall using
I will apologize in advance as this post is born out of severe frustration.
Sorry for the double post, I will update this question if I can't get
This post on SO answers most of the questions I have (much thanks to
This post is incorrectly tagged 'send' since I cannot create new tags. I have
Hope this post will not be killed on the ground of NOT PROGRAMMING RELATED.
Fist off, been lurking for years, hopefully this post will be helpful to more
I'm guessing that this post will hit a different group of people who seem
Okay...I'm really getting a bit frustrated with this. I know that this post will
This post will be lengthy and I apologize on beforehand for that. I'm trying

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.