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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T17:52:41+00:00 2026-06-10T17:52:41+00:00

I have ArrayList<ColorDrawable> colors = new ArrayList<ColorDrawable>(); for(int i = 0; i = intList.size();

  • 0

I have

ArrayList<ColorDrawable> colors = new ArrayList<ColorDrawable>();
for(int i = 0; i = intList.size(); i++){ //some list of ints
    colors.add(new ColorDrawable(intList.get(i)));

I want to fade from one color in the list to another, using a SurfaceView + Canvas method. Here’s my attempt:

 public void run() {
    int maxIndex = colors.size() - 1;
        while (isItOK) {
            for (int i = 0; i <= maxIndex; i++) {
                int color = colors.get(i).getColor();
                int nextColor = (i == maxIndex) ? colors.get(0).getColor() : colors.get(i + 1).getColor();

                if(color < nextColor) {
                    for(; color <= nextColor; color++) {
                        Canvas c = holder.lockCanvas();
                        c.drawColor(color);
                        holder.unlockCanvasAndPost(c);
                    }
                }


                if(color > nextColor) {
                    for(; color >= nextColor; color--) {
                        Canvas c = holder.lockCanvas();
                        c.drawColor(color);
                        holder.unlockCanvasAndPost(c);
                    }
                }
            }

        }
    }

I feel like this should work as is and fade from the first color the second to the third, and so on…and end up looping, but instead, it starts from the first color, and fades to some unrelated color, over and over. (I’ve tested different data as well). This is my first time working with a SurfaceView so I’m not sure if how I have done my canvas method is correct. Using Log.d, I saw that once it gets into one of the inner for loops (the ones with the “if” statements before them), it will not leave that for loop….which doesn’t make sense to me but I figure it has something to do with the canvas and holder. Help?

  • 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-10T17:52:43+00:00Added an answer on June 10, 2026 at 5:52 pm

    I’m not sure, if i understood you corretly, if not, please let me know.

    In my understanding you want to: loop through the colors and set each time the backgroundcolor as the i th element of your colors list.

    UPDATE: Note, that i havent tested it jet!

    int currentIndex = 0;
    int nextIndex = 0;
    
    while (isItOK) 
    {
        nextIndex = (currentIndex + 1) % colors.size();
    
        int currentColor = colors.get(currentIndex).getColor();
        int nextColor = colors.get(nextIndex).getColor();
        while(currentColor != nextColor)
        {
            //extract red, green, blue, alpha from the current color
    
            int r = Color.red(currentColor); //android.graphics.Color
            int g = Color.green(currentColor);
            int b = Color.blue(currentColor);
            int a = Color.alpha(currentColor);
    
            //extract the same from nextColor
            int nr = Color.red(nextColor);
            int ng = Color.green(nextColor);
            int nb = Color.blue(nextColor);
            int na = Color.alpha(nextColor);
    
            //get currentColors values closer to nextColor 
            r = (r<nr) ? r+1 : ((r>nr) ? r-1 : r);
            g = (g<ng) ? g+1 : ((g>ng) ? g-1 : g);
            b = (b<nb) ? b+1 : ((b>nb) ? b-1 : b);
            a = (a<na) ? a+1 : ((a>ar) ? a-1 : a);
    
            // generate currentColor back to a single int
            currentColor = Color.argb(a,r,g,b);
    
            // paint it 
            Canvas canvas = holder.lockCanvas();
            canvas.drawColor(currentColor );
            holder.unlockCanvasAndPost(canvas);
        }
        currentIndex = (currentIndex + 1) % colors.size();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Arraylist List<?> myList=new ArrayList(); myList = fetchQuery(); //fetches the list of
i have an arraylist and i want to add and remove many items at
I have this arrayList: ArrayList<ArrayList<Integer>> temporary = new ArrayList<ArrayList<Integer>>(); Some how I need to
I have an ArrayList of type GeoPoint. private List<GeoPoint> points = new ArrayList<GeoPoint>(); I
I have an arraylist called 'pri1', I want this array list to be available
I have an ArrayList of Products, that i want to add to My map
I have this arraylist: ArrayList ftd = new ArrayList(); ftd.Add(new string[]{ foo1.txt, 01.01.2011 });
I have arraylist myorderdata . I want to retrieve this arraylist to one String
I have an ArrayList of HashMap like this: ArrayList<HashMap<String, String>> playListSongs = new ArrayList<HashMap<String,
I have two arraylist with a number of model objects.I want to find the

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.