Search code examples
androidarraysfill

Multiple methods to fill String Array Java Android


Little question... Whats the difference in output between

private String[] mStrings={
     "http://a3.twimg.com/profile_images/670625317/aam-logo-v3-twitter.png",
     "http://a3.twimg.com/profile_images/740897825/AndroidCast-350_normal.png"
}

and

jArray = new JSONArray(result);
JSONObject json_data=null;
image = new String[jArray.length()];

for(int i=0;i<jArray.length();i++)
{
    json_data = jArray.getJSONObject(i);
    img = json_data.getString("Img");
    Arrays.fill(image, img);                    
} 

Because the first method works perfectly with my ListView (image + txt).. second method is the one i really need because i do not want any static images.

Thanks!


Solution

  • Change

    Arrays.fill(image, img); 
    

    to

    image[i] = img;
    

    Arrays.fill() fills the given array with the specified input - meaning all elements inside the array will be set to the same thing. In this scenario, it means all elements in the array will be the same url as the last Img value in the json.