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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:14:37+00:00 2026-05-31T16:14:37+00:00

I have a listview with an image and a textview and I am applying

  • 0

I have a listview with an image and a textview and I am applying alternative row color for the list view in my class named MyArrayAdaptor which extends ArrayAdapter<String>

When the listview loads first, the alternative row color appears, but after I scroll the listview items a bit faster the color get mixed, that is the second color overrides the first color.

How can I handle this case?

the class MyArrayAdaptor;

public class MyArrayAdaptor extends ArrayAdapter<String> {
     private  Activity context;
     private  String[] text1;   
     private  String[] image1;
     private int TextViewID;
     private int ImageViewID;
     private int LoyoutID;
     //private int[] colors = new int[] { 0xFFFFFFFF, 0xb2b2b2FF };
     // private int[] colors = new int[] { 0x30FF0000, 0x300000FF };
     private int[] colors = new int[] { 0x30FF0000, 0x30000000 };


     public MyArrayAdaptor(Activity context,int id, String[] text1,String[] image,int textViewID, int imageViewID) {        
     super(context,id, text1);  
     this.context = context;
     this.text1 = text1;    
     this.image1=image;
     this.TextViewID=textViewID;
     this.ImageViewID=imageViewID;
     this.LoyoutID=id;
     }

     // static to save the reference to the outer class and to avoid access to
     // any members of the containing class
     static class ViewHolder {
     public ImageView imageView;
     public TextView textView;

     }

     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
     // ViewHolder will buffer the assess to the individual fields of the row
     // layout

     ViewHolder holder;

     View rowView = convertView;     

     if (rowView == null) {      
     LayoutInflater inflater = context.getLayoutInflater();
     rowView = inflater.inflate(LoyoutID, null, true);
     //color
     if (position % 2 == 0) {
            rowView.setBackgroundColor(colors[0]);          
            }
         else {
            rowView.setBackgroundColor(colors[1]);      
         }  
     holder = new ViewHolder();  
     holder.textView = (TextView) rowView.findViewById(TextViewID); 
     holder.imageView = (ImageView) rowView.findViewById(ImageViewID);

     rowView.setTag(holder);

     } else {
     holder = (ViewHolder) rowView.getTag();
     }   
     holder.textView.setText(text1[position]);

     //holder.imageView.setImageDrawable(LoadImageFromWebOperations(image[position]));
     holder.imageView.setBackgroundResource(R.drawable.icon);

     return rowView;
     }

     private Drawable LoadImageFromWebOperations(String url)
     {
     try     
     {   
     InputStream is = (InputStream) new URL(url).getContent();   
     Drawable d = Drawable.createFromStream(is, "src name");

     return d;
     }catch (Exception e) {

     System.out.println("Exc="+e);

     return null;

     }}
    }
  • 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-31T16:14:38+00:00Added an answer on May 31, 2026 at 4:14 pm

    i think you should set your background color outside if(rowView == null) condition. For example: just above return rowView;

    ...
    
    rowView.setBackgroundColor((position%2 == 0)? colors[0] : colors[1]);
    
    return rowView;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have listView in which I inflate a row contain textview and button now
I have created a custom listview using adapter. Each row of the list view
I have a custom listview which display an image, textview and radio button. I
I have a listview which is customized to display an image and 2 textview.
I have a list view.Each row of the this listview is the following layout.How
I have a listview with custom row having a textview and a clickable image
I have a listview which includes 2 textviews and 1 imageview. Now, the image
I have one listview.which contain one image ,text and one button .i had creted
I have a listview with each row having a checkbox, imageview and text view
I have a listview which loads its data from sqlite database. Each row in

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.