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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:54:49+00:00 2026-06-13T21:54:49+00:00

Befor using the viewholder i was able to change the background of one element

  • 0

Befor using the viewholder i was able to change the background of one element (that with te position == numEmission) of my listview but now each tiem i scroll the colored item change and i can have even 3 colored item, can any one help me.

public class ItemAdapterProgramme extends ArrayAdapter<Programme> {

public ArrayList<Programme> resultats;
public Bitmap bm;
public Context context;
public ImageLoader imageLoader = ImageLoader.getInstance();
public DisplayImageOptions options;
static ViewHolder holder;
public  LayoutInflater mInflater ;
public int numEmission;
public Calendar c;
public int cHour;
Typeface typeface_date, typeface_title;

public ItemAdapterProgramme(Context context, ArrayList<Programme> resultat) {
    super(context, R.layout.feed_view_programme, resultat);
    this.context = context;
    resultats = resultat;
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    typeface_date = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto/Roboto-Medium.ttf");
    typeface_title = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto/Roboto-Condensed.ttf");
}

public View getView(final int position, View convertView, final ViewGroup parent) {

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.feed_view_programme,parent, false);
        holder = new ViewHolder();
        holder.image = (ImageView) convertView.findViewById(R.id.prog_logo);
        holder.titre = (TextView) convertView.findViewById(R.id.prog_title);
        holder.animator = (TextView) convertView.findViewById(R.id.prog_anim);
        holder.start = (TextView) convertView.findViewById(R.id.prog_start);
        holder.end = (TextView) convertView.findViewById(R.id.prog_end);
        holder.description = (TextView) convertView.findViewById(R.id.prog_description);
        holder.animator.setTypeface(typeface_date);
        holder.titre.setTypeface(typeface_title);
        holder.start.setTypeface(typeface_title);
        holder.end.setTypeface(typeface_title);
        holder.description.setTypeface(typeface_title);
        holder.pb = (ProgressBar) convertView.findViewById(R.id.prog_progressBar1);
        holder.relativeLout_emission = (RelativeLayout)convertView.findViewById(R.id.layout_prog);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.titre.setText(resultats.get(position).getTitle());
    holder.animator.setText(resultats.get(position).getAnimateur());
    holder.start.setText("Début: "+resultats.get(position).getStart());
    holder.end.setText("    Fin: "+resultats.get(position).getEnd());
    holder.description.setText(resultats.get(position).getDescription());




    File cacheDir = StorageUtils.getOwnCacheDirectory(context, "UniversalImageLoader/Cache");

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context)
    .denyCacheImageMultipleSizesInMemory()
    .offOutOfMemoryHandling()
    .memoryCache(new UsingFreqLimitedMemoryCache(2 * 1024 * 1024)) 
    .discCache(new UnlimitedDiscCache(cacheDir))
    .discCacheFileNameGenerator(new HashCodeFileNameGenerator())
    .imageDownloader(new URLConnectionImageDownloader(5 * 1000, 20 * 1000)) 
    .defaultDisplayImageOptions(DisplayImageOptions.createSimple())
    .enableLogging()
    .build();

    imageLoader.init(config);

    options = new DisplayImageOptions.Builder()
    .showStubImage(R.drawable.error)
    .showImageForEmptyUri(R.drawable.error)
    .cacheInMemory()
    .cacheOnDisc()
    .imageScaleType(ImageScaleType.IN_SAMPLE_INT)
    .build();

    imageLoader.displayImage(resultats.get(position).getImageUrl(),  holder.image, options, new ImageLoadingListener() {
        @Override
        public void onLoadingStarted() {
            holder.pb.setVisibility(View.VISIBLE);                  }
        @Override
        public void onLoadingFailed(FailReason failReason) {
            holder.pb.setVisibility(View.GONE);                 
        }
        @Override
        public void onLoadingComplete(Bitmap loadedImage) {
            holder.pb.setVisibility(View.GONE);                 
        }
        @Override
        public void onLoadingCancelled() {
            // Do nothing
        }
    });
    c = Calendar.getInstance();  
    cHour=c.get(Calendar.HOUR_OF_DAY);
    Log.d("Adapter cHour", cHour+"");
    numEmission=findEmission(cHour);
    Log.d("Adapter numEmission", numEmission+"");
    if(position==numEmission){
        holder.relativeLout_emission.setBackgroundColor(context.getResources().getColor(R.color.grey));
    }
    return convertView;
}

public int findEmission(int hour){
    for(int i=0;i < resultats.size()-1;i++){
        String start=resultats.get(i).getStart();
        String end=resultats.get(i).getEnd();
        String[] P0=start.split(":");
        String[] P1=end.split(":");
        start=P0[0];
        end=P1[0];
        int intStart=Integer.parseInt(start);
        int intEnd=Integer.parseInt(end);
        if(intStart<=hour && hour<=intEnd) {
            numEmission=i;
            break;
        }
    }
    return numEmission;
}

static class ViewHolder {
    TextView titre, animator, start, end, description;
    ImageView image;
    ProgressBar pb;
    RelativeLayout relativeLout_emission;
}
  • 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-13T21:54:50+00:00Added an answer on June 13, 2026 at 9:54 pm

    The problem is not in holder, but in convertView. ListView can use one convertView several times to increase perfomance. So if you colored item once, each time it is reused you will have one more colored item. You can remove holder and inflate new view each time, but it is not good to do so.

    Try modifiying your code like this

    if (position==numEmission) {
        holder.relativeLout_emission.setBackgroundColor(context.getResources().getColor(R.color.grey));
    } else {
        // set default background color
        holder.relativeLout_emission.setBackgroundColor(context.getResources().getColor(R.color.default_list_element_background));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've done some simple string -> DateTime conversions before using DateTime.ParseExact(), but I have
Background I would like my Python script to pause before exiting using something similar
The dilemma I'm using a before_filter in my controller that restricts access to admins.
I've got a script that sets some session values before redirecting to / using
How would I check that NSRegularExpressionSearch exists before using it? enum { NSCaseInsensitiveSearch =
As I talk about befor I'm using to jQuery to refresh / update a
I'm using: <?php $file = $_GET['page']; //ie: http://localhost/?page=index include php/{$file}.php; ?> But I need
I know similar questions have been asked many times befor, but I think this
i am using following code to display list of tags now when i select
I am currently trying to clean URL in my local machine(wamp) before using that(.htaccess)

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.