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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:57:00+00:00 2026-05-21T03:57:00+00:00

I am putting together some codes and attempting to assign a wallpaper with the

  • 0

I am putting together some codes and attempting to assign a wallpaper with the attached code.
The random image part works, the assign image to wallpaper works, but I do not see how to get the exact image shown to be the image for the wallpaper.

public class RandomImage extends Activity implements OnClickListener{

    private Integer [] mImageIds = { 
        R.drawable.big1, 
        R.drawable.big2, 
        R.drawable.big3, 
    };

    private static final Random rgenerator = new Random();
    private ImageView iv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.winner);

        Integer q = mImageIds[rgenerator.nextInt(mImageIds.length)];
        iv = (ImageView) findViewById(R.id.imageView1);
        iv.setImageResource(q);
        iv.setImageResource(mImageIds[rgenerator.nextInt(mImageIds.length)]);

        View setButton = findViewById(R.id.set_wallpaper);
        setButton.setOnClickListener(this);     
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.set_wallpaper:
                WallpaperManager myWallpaperManager = 
                    WallpaperManager.getInstance(getApplicationContext());
                try {     
                    //How to reference the image selected in above random array? 
                myWallpaperManager.setResource(????);   
                } catch (IOException e) { 
                    // TODO Auto-generated catch block     
                    e.printStackTrace();
                }
         }
     }
}
  • 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-21T03:57:01+00:00Added an answer on May 21, 2026 at 3:57 am

    Why not declaring an int class variable that stocks the id, e.g:

    int lastImageRef;
    

    …

    lastImageRef = mImageIds[rgenerator.nextInt(mImageIds.length)];
    iv.setImageResource(lastImageRef);
    

    …

    myWallpaperManager.setResource(lastImageRef); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm putting together some code to essentially replace the contents of a div when
I have tried putting together some code based on some other SO questions and
I am attempting to teach myself some JQuery/REST/Google API by putting together a simple
I am putting together a website in codeIgniter, but I'm having some trouble with
I need some help putting together this query in Django. I've simplified the example
I'm putting together a quick script to scrape a page for some results and
I'm just putting together a little POC project, and I'm having some weird issues
I'm putting together some demo pages, and one of the things I want to
I'm putting together a presentation to show some of the productivity gains that I
I am putting together a store finder which works on a radius from a

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.