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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:58:19+00:00 2026-06-10T11:58:19+00:00

I am writing a simple app that changes the application background randomly on button

  • 0

I am writing a simple app that changes the application background randomly on button click.

I have a arraylist that contains 5 id’s of images that the application should use:

    ArrayList<Integer> imageID = new ArrayList<Integer>();
    imageID.add(R.drawable.frame_blue);
    imageID.add(R.drawable.frame_green);
    imageID.add(R.drawable.frame_lilac);
    imageID.add(R.drawable.frame_pink);
    imageID.add(R.drawable.frame_yellow);

I have two buttons in my layout xml file for next and previous. Both should change Application background when clicked.

I change the image background from this arraylist:

iM.setBackgroundResource(imageID.get(r.nextInt(5)));

and my layout xml looks like:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/parentLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="76dp"
        android:onClick="previous"
        android:text="Previous" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/button1"
        android:layout_alignBottom="@+id/button1"
        android:layout_alignParentRight="true"
        android:onClick="next"
        android:text="Next" />

</RelativeLayout>

All works fine on button click’s, ImageView background change as I expect, but the problem is the background is not changing smoothly.

It hangs some time. May be the main ui thread will be block for 1 or 2 second and this look like application hangs.

Hangs mean: Some time button remain clicked for a few seconds.

I tried asynctask did not have success. Is there a way to make it change smoothly?

  • 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-10T11:58:21+00:00Added an answer on June 10, 2026 at 11:58 am

    you need to use caching in order to save time and not inflate every time the images
    like this : Drawable image_frame_green = getResources().getDrawable(
    R.drawable.frame_green);

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

Sidebar

Related Questions

I'm writing a simple web app in PHP that needs to have write access
I'm currently writing a simple app that performs a series of requests to the
I'm new to android and am writing a simple app that calculates the distance
I am currently writing a simple IOS app that saves tasks into a table.
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
I am currently writing a simple web app which needs to update form changes
Writing my first, very simple Rails application, a simple admin app to track work
I'm writing an app that contains the following tables: (1) employee_type, (2) employee and
I am writing a simple app used for communicating between a server and an
I'm writing a simple app with AppEngine, using Python. After a successful insert by

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.