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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:59:54+00:00 2026-05-26T05:59:54+00:00

I am having a little problem using different colors in a ListView . I

  • 0

I am having a little problem using different colors in a ListView.

I have tried several things but nothing seems to work

private class GameRowAdapter extends ArrayAdapter {
ArrayList objects;

    public GameRowAdapter(Context context, int textViewResourceId, ArrayList<RowModel> objects) {
        super(context, textViewResourceId, objects);
        this.objects = objects;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        RowModelViews model;
        if (row == null) {
            LayoutInflater inflater = LayoutInflater.from(GamePlayerActivity.this);
            row = inflater.inflate(R.layout.game_line_layout, null);
            model = new RowModelViews();
            model.entry = (TextView) row.findViewById(R.id.gameLineEntry);
            model.score = (TextView) row.findViewById(R.id.gameLineEntryScore);
            row.setTag(model);
        } else {
            model = (RowModelViews) row.getTag();
        }

        if (position == 6 || position == 7) {
            row.setBackgroundColor(R.color.black);
        } else {
            row.setBackgroundColor(R.color.light_transparent);
        }

        model.entry.setText(objects.get(position).entry);
        model.score.setText(objects.get(position).score);

        return row;
    }
}

static class RowModelViews {
    TextView entry;
    TextView score;

}

static class RowModel {
    String entry;
    String score;

    public RowModel(String entry, String score) {
        this.entry = entry;
        this.score = score;
    }
}

Anyone who can tell me, what I am doing wrong?

Thank you.

UPDATE

Here is the xml of the inflatet row

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:orientation="horizontal">
    <TextView android:id="@+id/gameLineEntry"
              android:layout_height="fill_parent"
              android:layout_width="fill_parent"
              android:layout_marginLeft="20dp"
              android:textSize="20dp"
              android:gravity="center_vertical"/>
    <TextView android:id="@+id/gameLineEntryScore"
              android:layout_height="fill_parent"
              android:layout_width="65dp"
              android:layout_marginRight="20dp"
              android:gravity="center"
              style="@style/Button"                  
              android:layout_gravity="right"/>
</LinearLayout>
  • 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-05-26T05:59:54+00:00Added an answer on May 26, 2026 at 5:59 am

    Edit: After running a small local test, I think the issue may be that the TextViews you have in each row are in front of the ListView row view. Try setting the model.entry and model.score background colors. /Edit

    I think it’s coming from the convertViews being reused. Try moving this:

    if (position == 6 || position == 7) {
        row.setBackgroundColor(R.color.black);
    }
    

    Outside of the if (row == null) block, and change it to this:

    if (position == 6 || position == 7) {
        model.entry.setBackgroundColor(R.color.black);
        model.score.setBackgroundColor(R.color.black);
    
    } else {
        model.entry.setBackgroundColor(/*Whatever your default background color is*/);
        model.score.setBackgroundColor(/*Whatever your default background color is*/);
    }
    

    So your full getView method would be:

     @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View row = convertView;
            RowModelViews model;
            if (row == null) {
                LayoutInflater inflater = LayoutInflater.from(GamePlayerActivity.this);
                row = inflater.inflate(R.layout.game_line_layout, null);
                model = new RowModelViews(row);
                model.entry = (TextView) row.findViewById(R.id.gameLineEntry);
                model.score = (TextView) row.findViewById(R.id.gameLineEntryScore);
                row.setTag(model);
            } else {
                model = (RowModelViews) row.getTag();
            }
    
            if (position == 6 || position == 7) {
                model.entry.setBackgroundColor(R.color.black);
                model.score.setBackgroundColor(R.color.black);
            } else {
                model.entry.setBackgroundColor(/*Whatever your default background color is*/);
                model.score.setBackgroundColor(/*Whatever your default background color is*/);
            }
    
            model.entry.setText(objects.get(position).entry);
            model.score.setText(objects.get(position).score);
    
            return row;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using NUnit (but have also tried this with VS testing) and I'm having
I'm having a little problem using NSURLDownload . Basically I'm downloading two different files
I'm having a little problem with nginx and the Perl FCGI module. I have
I’m having a little Architecture problem. In my project I have a Business Logic
I'm using a ViewPager in my project, and having a little problem at setting
I'm having a little problem with using conditionally evaluated expression in jsf/a4j Here's my
The problem I am having is a little hard to explain, but I will
I'm having a little problem and I don't see why, it's easy to go
I'm having a little problem with the following: When I execute this line: echo
I'm having a little problem with jQuery: I'm having .submit() defined on a form,

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.