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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:58:03+00:00 2026-05-20T14:58:03+00:00

i am trying to send an array containing strings of url of the image

  • 0

i am trying to send an array containing strings of url of the image source to the imageadapter of the grid view. But only the last url of the array is being used to set the image in the adapter. some help here would be appreciated.

GridView gridview = (GridView) findViewById(R.id.gridview);
    ImageAdapter imageListAdapter = null;
    for( int inx = 0 ; inx < imageUrl.length ; inx++)
        {
                 imageListAdapter = new ImageAdapter(context,imageUrl[inx],productName[inx] );
                 System.out.println(imageUrl[inx]);
                 System.out.println(productName[inx]);
                 gridview.setAdapter(imageListAdapter);
        }

adapter code :

public class ImageAdapter extends BaseAdapter {
private Context mContext;
static int i = 0;
String url = null;
String name = null;

public ImageAdapter(Context c, String url , String name ) {
    mContext = c;
    this.url = url;
    this.name = name;
}

public int getCount() {
    // return url.length;
    return ++i;
}

public Object getItem(int position) {
    return null;
}

public long getItemId(int position) {
    return 0;
}

// create a new ImageView for each item referenced by the Adapter
public View getView(final int position, View convertView, ViewGroup parent) {
    ImageView imageView;

    if (convertView == null) {  // if it's not recycled, initialise some attributes
        imageView = new ImageView(mContext);
        imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8,8,8,8);
    } else {
        imageView = (ImageView) convertView;
    }
    //imageView.setImageResource(mThumbIds[position]);
    //Bitmap bmp  = loadBitmap("http://www.xvr.com/aero/planes/boeing/boeingf15.jpg");

    Bitmap bmp  = loadBitmap(url);
    System.out.println("in adapter :"+url);
    //imageView.setImageResource(mThumbIds[position]);
    imageView.setImageBitmap(bmp);
    return imageView;
}
public static Bitmap loadBitmap(String url) 
{
    Bitmap bitmap = null;
    InputStream in = null;
    BufferedOutputStream out = null;

    try {
        in = new BufferedInputStream(new URL(url).openStream(),  4 * 1024);

        final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
        out = new BufferedOutputStream(dataStream,  4 * 1024);

        int byte_;
        while ((byte_ = in.read()) != -1)
            out.write(byte_);
        out.flush();

        final byte[] data = dataStream.toByteArray();
        BitmapFactory.Options options = new BitmapFactory.Options();
        //options.inSampleSize = 1;

        bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
    } catch (IOException e) {
        Log.e("","Could not load Bitmap from: " + url);
    } finally {
        try{
            in.close();
            out.close();
        }catch( IOException e )
        {
            System.out.println(e);
        }
    }
    return bitmap;
}

}

  • 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-20T14:58:03+00:00Added an answer on May 20, 2026 at 2:58 pm

    This is because you are creating new ImageAdapter every time in your for loop and setting it to Gridview so in the last iteration of your loop the last image is set to adapter and finally that adapter is set to gridview.

    Note: Your implementation is wrong have look at following example http://mobiforge.com/designing/story/understanding-user-interface-android-part-3-more-views and search for keyword GridView

    Pass url and name as string array just once rather than each time creating new object of ImageAdapter something like below, and change your adapter code accordingly.

    imageListAdapter = new ImageAdapter(context,imageUrl,productName);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to send a array to my method with $.post() but Im kinda
I am trying to receive a post array send from the view page by
I'm trying to send an array of hexadecimal values through an udp socket but
Trying to send array + vars with Ajax, Sending just the array worked fine...but
I'm trying to send an array of numbers over a TCP socket but they
I am trying to send a javascript array to an external php page, but
am trying send an array to php file using $_POST ,still always getting an
I am trying to send an array of this struct to a DBus Server:
I am trying to send the result of a split() function into an array
I'm trying to send a *var, that is in fact a 4 slot array,

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.