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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:05:47+00:00 2026-06-04T19:05:47+00:00

I want to Change the background image of ListView automatically after a time interval

  • 0

I want to Change the background image of ListView automatically after a time interval :
I using this code :

in side of onCreate(_) {

t = new Thread(){
            public void run() {
                for(int i=0; i<=5; i++){
                    Log.i("forrrrr ", i+"");
                    try {

                        if(flag == 0){
                        listV.setBackgroundDrawable(getResources().getDrawable(R.drawable.th2));
                        flag = 1;
                    }
                    else if(flag == 1){
                        listV.setBackgroundDrawable(getResources().getDrawable(R.drawable.th1));
                        flag = 0;
                    }
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        };
    };
    t.start();

}

but i got following Exception at run time :

05-31 13:30:23.832: INFO/AndroidRuntime(309): NOTE: attach of thread 'Binder Thread #3' failed
05-31 13:30:24.442: INFO/ARMAssembler(59): generated scanline__00000077:03545404_00000004_00000000 [ 47 ipp] (67 ins) at [0x2fc6d8:0x2fc7e4] in 5635232 ns
05-31 13:30:24.723: DEBUG/dalvikvm(315): GC_EXTERNAL_ALLOC freed 882 objects / 61160 bytes in 67ms
05-31 13:30:25.332: INFO/forrrrr(315): 0
05-31 13:30:25.452: DEBUG/dalvikvm(315): GC_EXTERNAL_ALLOC freed 248 objects / 11760 bytes in 113ms
05-31 13:30:25.992: INFO/ActivityManager(59): Displayed activity com.dev/.Android10Activity: 2234 ms (total 765300 ms)
05-31 13:30:27.675: INFO/forrrrr(315): 1
05-31 13:30:27.675: WARN/dalvikvm(315): threadid=7: thread exiting with uncaught exception (group=0x4001d800)
05-31 13:30:27.675: ERROR/AndroidRuntime(315): FATAL EXCEPTION: Thread-8
05-31 13:30:27.675: ERROR/AndroidRuntime(315): java.lang.UnsupportedOperationException: removeAllViews() is not supported in AdapterView
05-31 13:30:27.675: ERROR/AndroidRuntime(315):     at android.widget.AdapterView.removeAllViews(AdapterView.java:511)
05-31 13:30:27.675: ERROR/AndroidRuntime(315):     at com.dev.Android10Activity$1.run(Android10Activity.java:61)
05-31 13:30:27.693: WARN/ActivityManager(59):   Force finishing activity com.dev/.Android10Activity

If i used a button and change manually it working well like this :

button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(flag == 0){
                    listV.setBackgroundDrawable(getResources().getDrawable(R.drawable.th2));
                    flag = 1;
                }
                else if(flag == 1){
                    listV.setBackgroundDrawable(getResources().getDrawable(R.drawable.th1));
                    flag = 0;
                }               
            }
        });
  • 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-04T19:05:48+00:00Added an answer on June 4, 2026 at 7:05 pm

    You can’t affect UI elements from a thread which is not a “UI Thread”.
    You should run this code using Activity.runOnUiThread
    or use a Handler like in this example

    Here’s another article that may be useful

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

Sidebar

Related Questions

i have many div's with the same background image and i want change this
I want to change width of background image of div on hover. My code
I want to change background image of button on mousehover event. I am using
I want to change the background image using slow animation, but its not working
I want to change the background image of the activity after every 30 seconds
how to add a background image to my asp:linkbutton using code behind? I want
I want to change my background image of my html on every refresh. This
I want to change the background image of a button using Javascript. Here is
I want to change the background image for the panorama view in the WP7
I want to change background color of image view randomly i don't want to

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.