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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:04:26+00:00 2026-05-26T01:04:26+00:00

I am trying to write a simple application that loads images that are stored

  • 0

I am trying to write a simple application that loads images that are stored in a web directory I’ve created. I want the application to grab ALL of the images that are stored in said directory and display them in a layout.

The code below works for only certain type of URLs(mainly tinypic, but not photobucket, imageshack etc) and also not for directories.

I’ve my image names formatted in sequence like image1.png, image2.png, etc. so that the code snippet and the downloadFile()-method would work.

But, I’m not sure how I would grab all the images from the server simultaneously because this only grabs one image at a time, sets it as a bitmap and then displays it in an IV. I’m pretty new to Android so some help in the right direction would be appreciated.

public class NewWallpapersActivity extends Activity {

    ImageView imView1;
    String imageUrl="http://i133.photobucket.com/albums/q44/slimjady/Wallpapers";
    Random r= new Random();

    /** Called when the activity is first created. */ 
    @Override
    public void onCreate(Bundle SavedInstanceState) {
        super.onCreate(SavedInstanceState);
        setContentView(R.layout.newwallpapers);

        Button bt3= (Button)findViewById(R.id.get_imagebt);
        bt3.setOnClickListener(getImgListener);
        imView1 = (ImageView)findViewById(R.id.IV1);
    }    

    View.OnClickListener getImgListener = new View.OnClickListener(){

        public void onClick(View view) {
            //i tried to randomize the file download, in my server i put 4 files with name like
            //png0.png, png1.png, png2.png so different file is downloaded in button press
            int i =r.nextInt(4);
            downloadFile(imageUrl+"png"+i+".png");
            Log.i("im url",imageUrl+"png"+i+".png");
        }

    };

    Bitmap bmImg;

    void downloadFile(String fileUrl){
        URL myFileUrl = null;          
        try {
            myFileUrl= new URL(fileUrl);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        try {
            HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
            conn.setDoInput(true);
            conn.connect();
            InputStream is = conn.getInputStream();

            bmImg = BitmapFactory.decodeStream(is);
            imView1.setImageBitmap(bmImg);
        } catch (IOException e) {
            String exception = "Erro: An Exception Was Thrown";
            Toast errortoast = Toast.makeText(this, exception, Toast.LENGTH_SHORT);
            errortoast.show();
            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-26T01:04:27+00:00Added an answer on May 26, 2026 at 1:04 am

    Here are some thoughts on this one:

    Displaying all Images

    Since you want to display all Images from within a single folder, I would suggest you to have a Directory-Activity, which displayes all the images in the given directory and one Image-Activity which displays only one single Image.

    To proper present this I would suggest using a GridView to display all the Images and a normal Activity with a full-screen ImageView to display the single Image.

    You could also use the Gallery-widget to “combine” both those ideas.

    Not letting the user wait

    One of the bigger problems with your approach is, that the images are getting downloaded on the UI-Thread.

    Depending on the size of all or on single image and the available connection-speed, Downloading the image can take a while. While the images are getting downloaded, the UI-Thread will wait for your downloadStuff()-method to return and the UI will freeze. This might create the illusion that your App just crashed.

    So, you’ll want to do the downloading in a separate thread. Android has a handy wrapper for this called an AsyncTask.

    As a little bonus to show your user that the process might take a while you can use a ProgressDialog to illustrate this (on the UI-Thread).

    Knowing whats in a directory

    Now we come to the point where we have to face some limitations. If you want to use Picture-Hosters like the ones you listed above, you’ll need to check if they offer you an API (or something equal) to get a list of Images (or their URLs) from a certain directory/album (look for a “API”-link on the front-page).

    If you host the images on your own Server, you should be able to create a little PHP-script (or whatever script/programming language you prefer), which then lists all image-files in the directory and presents them in an easy-to-parse way (either JSON or XML).

    This should enable you to get a list of URLs to the Image-files you want to display.

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

Sidebar

Related Questions

I am trying to write a simple application that runs on a Windows Mobile
I am trying to write a simple application that gets updated. For this I
I am trying to write a simple matrixMultiplication application that multiplies two square matrices
I am trying to write a very simple Android application that checks the signal
I am trying to write a simple application that monitors the COM port and
I'm trying to write a simple application that finds out who liked your page.
I'm trying to write what I hope is a simple application tracker. That is,
I'm trying to write a simple winforms application that executes a SQL SELECT statement
I am trying to write a very simple application that allows me to enter
I've been trying to write a simple Static-class State Machine for my application 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.