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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:50:18+00:00 2026-06-16T17:50:18+00:00

I have a custom listview by using an adapter which has alternate background color.

  • 0

I have a custom listview by using an adapter which has alternate background color.
The problem is that the text which are strings (over 100+ of strings) are set to the color of Color.BLACK but in the listview the first couple of strings are white and then the rest are black.

@Override  
    public View getView(int position, View convertView, ViewGroup parent) {  
    View view = super.getView(position, convertView, parent);  
    TextView tv = (TextView) super.getView(position, convertView, parent);
    int colorPos = position % color.length; 
    tv.setTextColor(Color.BLACK);
    view.setBackgroundColor(color[colorPos]);  
    return view;  
}  

I can’t detect the problem why the first are white then the others are black, is it something to with loading or something? because my text (the strings) they are over 100.

UPDATE

This is the listView code:

MyAdapter adapter = new MyAdapter(this, 
    android.R.layout.simple_list_item_1,
    Strings.Advices);
setListAdapter(adapter);

And the strings:

public class Strings {
    public static String Advices[] = {
       "advice",
       "advice",
       "adc",
       "add",
    };
}  
  • 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-16T17:50:19+00:00Added an answer on June 16, 2026 at 5:50 pm

    Your TextView does nothing. Typically you need to use findViewById() to locate the TextView in your row’s layout. Since you are using android.R.layout.simple_list_item_1 which is a TextView itself, we can skip that step:

    @Override  
    public View getView(int position, View convertView, ViewGroup parent) {  
        View view = super.getView(position, convertView, parent);  
        TextView tv = (TextView) view;
        int colorPos = position % color.length; 
        tv.setTextColor(Color.BLACK);
        view.setBackgroundColor(color[colorPos]);  
        return view;  
    }  
    

    But the getView() method of any built-in Adapter is very generic, therefor slow… You should write your own to take full advantage of the Adapter’s recycler and the ViewHolder concept. Please watch this Google Talk Turbo Charge Your UI (and/or the World of ListView) to help you write an efficient adapter.

    The problem is that the text which are strings ( over 100+ of strings ) are set to the color of Color.BLACK but in the listview the first couple of strings are white and then the rest are black

    I assume that this change happens when you scroll the ListView, this is directly linked to how the View recycler behaves.

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

Sidebar

Related Questions

We have created custom listview by using the Base adapter. List view contains Text
I have a button that should sort a ListView using a custom adapter. The
I have a Custom ListView which has an ImageView and a TextView. and i
I have a listview with a custom arrayadapter that handles about 15 strings. The
I have a custom cursor adapter I'm using to fill a ListView. The inflater
I am using custom adapter which I use for my ListView . After creating
I have a ListView which uses a custom adapter to display rows of data.
I'm trying to delete items from a ListView using a custom adapter which extends
I have a listView using a custom adapter. Each row contains a button and
I have displayed itemimage and itemname in custom listview using base adapter class. I

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.